ConvertEventArgs.DesiredType Propriété

Définition

Obtient le type de données de la valeur souhaitée.

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

Valeur de propriété

Type

Type de la valeur souhaitée.

Exemples

L’exemple de code suivant utilise la DesiredType propriété pour déterminer si la conversion d’un type en un autre peut continuer. La DecimalToCurrencyString méthode teste si la DesiredType chaîne est une chaîne. Si ce n’est pas le cas, le code quitte la méthode. De même, la CurrencyStringToDecimal méthode teste si la DesiredType valeur est un Decimal, et se ferme si ce n’est pas truele cas .

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

Remarques

La DesiredType propriété vous permet de vérifier le type de la propriété vers laquelle la valeur est convertie.

S’applique à