TypeConverter.CanConvertFrom TypeConverter.CanConvertFrom TypeConverter.CanConvertFrom TypeConverter.CanConvertFrom Method

定義

傳回一個值,指出這個轉換子是否可將某一型別的物件轉換為這個轉換子的型別。Returns whether this converter can convert an object of one type to the type of this converter.

多載

CanConvertFrom(Type) CanConvertFrom(Type) CanConvertFrom(Type) CanConvertFrom(Type)

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

CanConvertFrom(ITypeDescriptorContext, Type) CanConvertFrom(ITypeDescriptorContext, Type) CanConvertFrom(ITypeDescriptorContext, Type) CanConvertFrom(ITypeDescriptorContext, Type)

會傳回這個轉換子是否可以使用指定內容,將指定型別的物件轉換為這個轉換子的型別。Returns whether this converter can convert an object of the given type to the type of this converter, using the specified context.

CanConvertFrom(Type) CanConvertFrom(Type) CanConvertFrom(Type) CanConvertFrom(Type)

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

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

參數

sourceType
Type Type Type Type

Type,表示要轉換的來源型別。A Type that represents the type you want to convert from.

傳回

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

備註

在這個類別中實作時,這個方法永遠傳回 falseAs implemented in this class, this method always returns false. 它永遠不會傳回trueIt never returns true.

CanConvertFrom(ITypeDescriptorContext, Type) CanConvertFrom(ITypeDescriptorContext, Type) CanConvertFrom(ITypeDescriptorContext, Type) CanConvertFrom(ITypeDescriptorContext, Type)

會傳回這個轉換子是否可以使用指定內容,將指定型別的物件轉換為這個轉換子的型別。Returns whether this converter can convert an object of the given type to the type of this converter, using the specified context.

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

參數

sourceType
Type Type Type Type

Type,表示要轉換的來源型別。A Type that represents the type you want to convert from.

傳回

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

備註

在這個類別中實作時,這個方法會傳回false,除非sourceTypeInstanceDescriptorAs implemented in this class, this method returns false, unless sourceType is an InstanceDescriptor.

給繼承者的注意事項

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

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.

另請參閱

適用於