ConvertEventArgs.DesiredType Özellik

Tanım

İstenen değerin veri türünü alır.

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

Özellik Değeri

Type

Type İstenen değerin değeri.

Örnekler

Aşağıdaki kod örneği, bir türü başka DesiredType bir türe dönüştürme işleminin devam edip etmeyeceğini belirlemek için özelliğini kullanır. yöntemi, DecimalToCurrencyString öğesinin DesiredType bir dize olup olmadığını sınar. Aksi takdirde kod yönteminden çıkar. Benzer şekilde, yöntemi öğesinin CurrencyStringToDecimal DesiredType olup Decimalolmadığını test eder ve değilse çıkışını alır 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

Açıklamalar

özelliği, DesiredType değerin dönüştürüldüğü özelliğin türünü denetlemenizi sağlar.

Şunlara uygulanır