ConfigurationConverterBase.CanConvertFrom 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
确定是否允许转换。
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
参数
ITypeDescriptorContext用于类型转换的对象。
返回
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 确定是否可以对强类型属性执行转换,以获取配置文件中使用的值字符串。