ConvertEventArgs.DesiredType Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the data type of the desired value.
public:
property Type ^ DesiredType { Type ^ get(); };
public Type DesiredType { get; }
public Type? DesiredType { get; }
member this.DesiredType : Type
Public ReadOnly Property DesiredType As Type
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
.
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
Remarks
The DesiredType property enables you to check the type of the property that the value is being converted to.
Applies to
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기