I see that the usual TypeConverter code checks for type based on Type.FullName string. This made me wondering whether this is the fastest way to do it.
It turns out, based on a simple test, that it could be roughly 19 times faster if compared against actual types instead.
Below is my test case. On my computer first method ends after 574ms while the improved one takes 34ms (1m iterations).
private static bool Compare(Type destinationType)
{
switch (destinationType.FullName)
{
case "System.Int64":
case "System.Int32":
return true;
default:
return false;
}
}
private static bool Compare2(Type type)
{
return type == typeof(long) || type == typeof(int);
}