static private bool CanConvert(Type from, Type to)
{
if (from.IsPrimitive && to.IsPrimitive)
{
TypeCode typeCodeFrom = Type.GetTypeCode(from);
TypeCode typeCodeTo = Type.GetTypeCode(to);
if (typeCodeFrom == typeCodeTo)
return true;
if (typeCodeFrom == TypeCode.Char)
switch (typeCodeTo)
{
case TypeCode.UInt16: return true;
case TypeCode.UInt32: return true;
case TypeCode.Int32: return true;
case TypeCode.UInt64: return true;
case TypeCode.Int64: return true;
case TypeCode.Single: return true;
case TypeCode.Double: return true;
default: return false;
}
// Possible conversions from Byte follow.
if (typeCodeFrom == TypeCode.Byte)
switch (typeCodeTo)
{
case TypeCode.Char: return true;
case TypeCode.UInt16: return true;
case TypeCode.Int16: return true;
case TypeCode.UInt32: return true;
case TypeCode.Int32: return true;
case TypeCode.UInt64: return true;
case TypeCode.Int64: return true;
case TypeCode.Single: return true;
case TypeCode.Double: return true;
default: return false;
}
// Possible conversions from SByte follow.
if (typeCodeFrom == TypeCode.SByte)
switch (typeCodeTo)
{
case TypeCode.Int16: return true;
case TypeCode.Int32: return true;
case TypeCode.Int64: return true;
case TypeCode.Single: return true;
case TypeCode.Double: return true;
default: return false;
}
// Possible conversions from UInt16 follow. "sp; case TypeCode.Double: return true;
default: return false;
}
// Possible conversions from Single follow.
if (typeCodeFrom == TypeCode.Single)
switch (typeCodeTo)
{
case TypeCode.Double: return true;
default: return false;
}
}
return false;
}