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

参数

context
ITypeDescriptorContext ITypeDescriptorContext ITypeDescriptorContext ITypeDescriptorContext

一个 ITypeDescriptorContext,用于提供格式上下文。An ITypeDescriptorContext that provides a format context.

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.

另请参阅

适用于