语言

ConfigurationConverterBase.CanConvertFrom 方法

定义

确定是否允许转换。

public:
 override bool CanConvertFrom(System::ComponentModel::ITypeDescriptorContext ^ ctx, Type ^ type);
public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext ctx, Type type);
override this.CanConvertFrom : System.ComponentModel.ITypeDescriptorContext * Type -> bool
Public Overrides Function CanConvertFrom (ctx As ITypeDescriptorContext, type As Type) As Boolean

参数

ctx
ITypeDescriptorContext

ITypeDescriptorContext用于类型转换的对象。

type
Type

要从中 Type 转换。

返回

true 如果允许转换,则为否则,为 false.

示例

以下示例代码演示如何重写 CanConvertFrom 方法以创建自定义 TimeSpan 转换器类型。 此外,该示例演示如何在自定义节中使用此类型。

public override bool CanConvertFrom(
    ITypeDescriptorContext ctx, Type type)
{
    return (type == typeof(string));
}
Public Overrides Function CanConvertFrom( _
ByVal ctx As ITypeDescriptorContext, _
ByVal type As Type) As Boolean
    Return (type.ToString() = GetType(String).ToString())

End Function 'CanConvertFrom

注解

该方法 CanConvertFrom 确定是否可以对强类型属性执行转换,以获取配置文件中使用的值字符串。

适用于