TypeConverter.CanConvertTo 方法

定義

傳回值,指出這個轉換子是否可以將物件轉換成指定的型別。Returns whether this converter can convert the object to the specified type.

多載

CanConvertTo(Type)

傳回值,指出這個轉換子是否可以將物件轉換成指定的型別。Returns whether this converter can convert the object to the specified type.

CanConvertTo(ITypeDescriptorContext, Type)

傳回這個轉換器是否可以使用指定的內容,將物件轉換成指定的類型。Returns whether this converter can convert the object to the specified type, using the specified context.

CanConvertTo(Type)

傳回值,指出這個轉換子是否可以將物件轉換成指定的型別。Returns whether this converter can convert the object to the specified type.

public:
 bool CanConvertTo(Type ^ destinationType);
public bool CanConvertTo (Type destinationType);
member this.CanConvertTo : Type -> bool
Public Function CanConvertTo (destinationType As Type) As Boolean

參數

destinationType
Type

Type,代表您想要轉換成的類型。A Type that represents the type you want to convert to.

傳回

如果這個轉換子可以執行轉換,則為 true,否則為 falsetrue if this converter can perform the conversion; otherwise, false.

備註

如果destinationType是字串, 則的預設CanConvertTo執行一律true會傳回。If destinationType is a string, the default implementation of CanConvertTo always returns true.

CanConvertTo(ITypeDescriptorContext, Type)

傳回這個轉換器是否可以使用指定的內容,將物件轉換成指定的類型。Returns whether this converter can convert the object to the specified type, using the specified context.

public:
 virtual bool CanConvertTo(System::ComponentModel::ITypeDescriptorContext ^ context, Type ^ destinationType);
public virtual bool CanConvertTo (System.ComponentModel.ITypeDescriptorContext context, Type destinationType);
abstract member CanConvertTo : System.ComponentModel.ITypeDescriptorContext * Type -> bool
override this.CanConvertTo : System.ComponentModel.ITypeDescriptorContext * Type -> bool
Public Overridable Function CanConvertTo (context As ITypeDescriptorContext, destinationType As Type) As Boolean

參數

context
ITypeDescriptorContext

提供格式內容的 ITypeDescriptorContextAn ITypeDescriptorContext that provides a format context.

destinationType
Type

Type,代表您想要轉換成的類型。A Type that represents the type you want to convert to.

傳回

如果這個轉換子可以執行轉換,則為 true,否則為 falsetrue if this converter can perform the conversion; otherwise, false.

備註

context 參數可以用於擷取環境的其他資訊,而這個轉換子就是從該環境叫用的。Use the context parameter to extract additional information about the environment from which this converter is invoked. 這個參數可以是null, 所以請一律檢查它。This parameter can be null, so always check it. 甚至,內容物件上的屬性可能會傳回 nullAlso, properties on the context object can return null.

如果destinationType是字串, 則的預設CanConvertTo執行一律true會傳回。If destinationType is a string, the default implementation of CanConvertTo always returns true.

給繼承者的注意事項

請覆寫這個方法以提供您自己的轉換需求。Override this method to provide your own conversion requirements.

另請參閱

適用於