コード例 #1
0
        private void PerformValueConversion(ref object value, out string valueRetrievalFailureMessage)
        {
            valueRetrievalFailureMessage = null;

            if (this.integrationProxy.ProvidesCustomValueConversion)
            {
                ValueConvertEventArgs eventArgs = new ValueConvertEventArgs(value,
                                                                            this.validatedProperty.PropertyType,
                                                                            this.integrationProxy,
                                                                            this.validatedProperty.Name);
                this.integrationProxy.PerformCustomValueConversion(eventArgs);

                if (eventArgs.ConversionErrorMessage == null)
                {
                    value = eventArgs.ConvertedValue;
                }
                else
                {
                    value = null;
                    valueRetrievalFailureMessage = eventArgs.ConversionErrorMessage;
                }
            }
            else
            {
                if (value != null)
                {
                    if (value.GetType() == this.validatedProperty.PropertyType)
                    {
                        return;
                    }

                    try
                    {
                        TypeConverter converter = TypeDescriptor.GetConverter(this.validatedProperty.PropertyType);
                        value = converter.ConvertFrom(null, CultureInfo.CurrentCulture, value);
                    }
                    catch (Exception e)
                    {
                        if (e.InnerException is FormatException)
                        {
                            value = null;
                            valueRetrievalFailureMessage = string.Format(
                                CultureInfo.CurrentCulture,
                                Resources.ErrorCannotPerfomDefaultConversion,
                                value,
                                this.validatedProperty.PropertyType.FullName);
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
            }
        }
	protected void CustomConvert(object sender, ValueConvertEventArgs args)
	{
		string valueToConvert = args.ValueToConvert as string;

		if (valueToConvert != null)
		{
			char[] chars = valueToConvert.ToCharArray();
			Array.Reverse(chars);
			args.ConvertedValue = Int32.Parse(new string(chars));
		}
		else
		{
			args.ConvertedValue = null;
		}
	}
コード例 #3
0
    protected void dateOfBirthValidator_ValueConvert(object sender, Microsoft.Practices.EnterpriseLibrary.Validation.Integration.ValueConvertEventArgs e)
    {
        string   value = e.ValueToConvert as string;
        DateTime convertedValue;

        bool success = DateTime.TryParse(value, System.Globalization.CultureInfo.CurrentCulture, System.Globalization.DateTimeStyles.None, out convertedValue);

        if (success)
        {
            e.ConvertedValue = convertedValue;
        }
        else
        {
            e.ConversionErrorMessage = "Date Of Birth is not in the correct format.";
            e.ConvertedValue         = null;
        }
    }
コード例 #4
0
    protected void rewardsPointsValidator_ValueConvert(object sender, Microsoft.Practices.EnterpriseLibrary.Validation.Integration.ValueConvertEventArgs e)
    {
        string value = e.ValueToConvert as string;
        int    convertedValue;

        bool success = Int32.TryParse(value, out convertedValue);

        if (success)
        {
            e.ConvertedValue = convertedValue;
        }
        else
        {
            e.ConversionErrorMessage = "Rewards points is not a valid integer";
            e.ConvertedValue         = null;
        }
    }
コード例 #5
0
		private void PerformValueConversion(ref object value, out string valueRetrievalFailureMessage)
		{
			valueRetrievalFailureMessage = null;

			if (this.integrationProxy.ProvidesCustomValueConversion)
			{
				ValueConvertEventArgs eventArgs = new ValueConvertEventArgs(value,
					this.validatedProperty.PropertyType,
					this.integrationProxy,
					this.validatedProperty.Name);
				this.integrationProxy.PerformCustomValueConversion(eventArgs);

				if (eventArgs.ConversionErrorMessage == null)
				{
					value = eventArgs.ConvertedValue;
				}
				else
				{
					value = null;
					valueRetrievalFailureMessage = eventArgs.ConversionErrorMessage;
				}
			}
			else
			{
				if (value != null)
				{
					if (value.GetType() == this.validatedProperty.PropertyType)
					{
						return;
					}

					try
					{
						TypeConverter converter = TypeDescriptor.GetConverter(this.validatedProperty.PropertyType);
						value = converter.ConvertFrom(null, CultureInfo.CurrentCulture, value);
					}
					catch (Exception e)
					{
						if (e.InnerException is FormatException)
						{
							value = null;
							valueRetrievalFailureMessage = string.Format(
								CultureInfo.CurrentCulture,
								Resources.ErrorCannotPerfomDefaultConversion,
								value,
								this.validatedProperty.PropertyType.FullName);
						}
						else
						{
							throw;
						}
					}
				}
			}

		}
 public void PerformCustomValueConversion(ValueConvertEventArgs e)
 {
     if (ValueConvert != null)
     {
         ValueConvert(this, e);
     }
 }
 void OnValueConvertWithFailure(object source,
                                ValueConvertEventArgs e)
 {
     valueToConvert = e.ValueToConvert;
     originalConvertedValue = e.ConvertedValue;
     e.ConversionErrorMessage = conversionErrorMessage;
 }
 void OnValueConvert(object source,
                     ValueConvertEventArgs e)
 {
     valueToConvert = e.ValueToConvert;
     originalConvertedValue = e.ConvertedValue;
     e.ConvertedValue = convertedValue;
 }
	protected void CustomConvert(object sender, ValueConvertEventArgs args)
	{
		args.ConversionErrorMessage = "custom conversion error message";
	}
コード例 #10
0
		/// <summary>
        /// Performs the custom value conversion.
        /// </summary>
        /// <param name="e">The <see cref="T:Microsoft.Practices.EnterpriseLibrary.Validation.Integration.ValueConvertEventArgs"/> instance containing the event data.</param>
		public void PerformCustomValueConversion(ValueConvertEventArgs e)
		{
			throw new NotSupportedException("The method or operation is not supported.");
		}
コード例 #11
0
 public void PerformCustomValueConversion(ValueConvertEventArgs e)
 {
 }
コード例 #12
0
        protected void AmountValueConvert(object sender, ValueConvertEventArgs e)
        {
            double convertedValue;

            if (double.TryParse(e.ValueToConvert as string, NumberStyles.AllowDecimalPoint, NumberFormatInfo.CurrentInfo, out convertedValue))
            {
                e.ConvertedValue = convertedValue;
            }
            else
            {
                e.ConversionErrorMessage = Properties.Resources.AmountRangeTypeValidation;
                e.ConvertedValue = null;
            }
        }
コード例 #13
0
 void IValidationIntegrationProxy.PerformCustomValueConversion(ValueConvertEventArgs e)
 {
     if (Converter != null)
     {
         try
         {
             e.ConvertedValue = Converter.ConvertBack(e.ValueToConvert, e.TargetType, ConverterParameter,
                                                      ConverterCulture);
         }
         catch (Exception x)
         {
             e.ConversionErrorMessage = x.Message;
         }
     }
 }