ConvertEventArgs.DesiredType Propiedad

Definición

Obtiene el tipo de datos del valor deseado.Gets the data type of the desired value.

public:
 property Type ^ DesiredType { Type ^ get(); };
public Type DesiredType { get; }
member this.DesiredType : Type
Public ReadOnly Property DesiredType As Type

Valor de propiedad

Type

Type del valor deseado.The Type of the desired value.

Ejemplos

En el ejemplo de código siguiente DesiredType se usa la propiedad para determinar si la conversión de un tipo a otro puede continuar.The following code example uses the DesiredType property to determine whether the conversion of one type to another can proceed. El DecimalToCurrencyString método comprueba si DesiredType es una cadena.The DecimalToCurrencyString method tests whether the DesiredType is a string. En caso contrario, el código sale del método.If not, the code exits the method. Del mismo modo, el CurrencyStringToDecimal método comprueba si DesiredType es un Decimal y se cierra si no lo es true .Similarly, the CurrencyStringToDecimal method tests whether the DesiredType is a Decimal, and exits if it is not true.

private:
   void DecimalToCurrencyString( Object^ /*sender*/, ConvertEventArgs^ cevent )
   {
      // The method converts only to string type. 
      if ( cevent->DesiredType != String::typeid )
      {
         return;
      }

      cevent->Value = ( (Decimal^)(cevent->Value) )->ToString( "c" );
   }

   void CurrencyStringToDecimal( Object^ /*sender*/, ConvertEventArgs^ cevent )
   {
      // The method converts only to decimal type.
      if ( cevent->DesiredType != Decimal::typeid )
      {
         return;
      }

      cevent->Value = Decimal::Parse( cevent->Value->ToString(),
         NumberStyles::Currency, nullptr );
   }
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);
}

Private Sub DecimalToCurrencyString(sender As Object, cevent As ConvertEventArgs)
   ' The method converts only to string type. 
   If cevent.DesiredType IsNot GetType(String) Then
      Return
   End If 
   cevent.Value = CDec(cevent.Value).ToString("c")
End Sub 
 
 
Private Sub CurrencyStringToDecimal(sender As Object, cevent As ConvertEventArgs)
   ' The method converts only to decimal type.
   If cevent.DesiredType IsNot GetType(Decimal) Then
      Return
   End If 
 cevent.Value = Decimal.Parse(cevent.Value.ToString, _
 NumberStyles.Currency, nothing)
End Sub 

Comentarios

La DesiredType propiedad permite comprobar el tipo de la propiedad a la que se está convirtiendo el valor.The DesiredType property enables you to check the type of the property that the value is being converted to.

Se aplica a