I am using reflection and I want to do conversion checking for exception handling.
I need to check if string can convert to unknown type in my project.
I used :
TypeConverter t = TypeDescriptor.GetConverter(typeof(string));
Console.WriteLine(t.CanConvertTo(typeof(int)));
but it returns false !
or even this one returns false again :
StringConverter stringConverter = new StringConverter();
Console.WriteLine(stringConverter.CanConvertTo(typeof(int)));
my quesion is that why StringConverter returns false for converting string to int ???
EDIT :
I use this code to convert string to unknown types : ( result is string )
resultCastedToTargetPropertyType = Convert.ChangeType(result,propertyInfo.PropertyType);