you should modify your codes as below:
class My
{
}
// You should add the below line
[TypeConverter(typeof(MyConverter))]
class MyConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string);
}
}
class Program
{
static void Main(string[] args)
{
// Because your MyConverter inherits from TypeConverter
Console.WriteLine(TypeDescriptor.GetConverter(typeof(MyConverter)).CanConvertFrom(typeof(string)));
Console.Read();
}
}
The above codes print "True".
If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. My sample
No comments:
Post a Comment