ConvertEventArgs.DesiredType Property

Definition

Gets the data type of the desired value.

C#
public Type DesiredType { get; }
C#
public Type? DesiredType { get; }

Property Value

The Type of the desired value.

Examples

The following code example uses the DesiredType property to determine whether the conversion of one type to another can proceed. The DecimalToCurrencyString method tests whether the DesiredType is a string. If not, the code exits the method. Similarly, the CurrencyStringToDecimal method tests whether the DesiredType is a Decimal, and exits if it is not true.

C#
private void DecimalToCurrencyString(object sender, ConvertEventArgs cevent)
{
   // The method converts only to string type. 
   if(cevent.DesiredType != typeof(string)) return;

   cevent.Value = ((decimal) cevent.Value).ToString("c");
}

private void CurrencyStringToDecimal(object sender, ConvertEventArgs cevent)
{   
   // The method converts only to decimal type.
   if(cevent.DesiredType != typeof(decimal)) return;

   cevent.Value = Decimal.Parse(cevent.Value.ToString(),
   NumberStyles.Currency, null);
}

Remarks

The DesiredType property enables you to check the type of the property that the value is being converted to.

Applies to

Өнім Нұсқалар
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9