internal static Type ConvertNumericType(Type expressionType, Type expectedType)
{
var expectedType_ = Type.GetTypeCode(Nullable.GetUnderlyingType(expectedType) ?? expectedType);
switch (Type.GetTypeCode(Nullable.GetUnderlyingType(expressionType) ?? expressionType))
{
case TypeCode.Char:
switch (expectedType_)
{
case TypeCode.Char:
case TypeCode.UInt16:
case TypeCode.Int32:
case TypeCode.UInt32:
case TypeCode.Int64:
case TypeCode.UInt64:
case TypeCode.Single:
case TypeCode.Double:
case TypeCode.Decimal:
return expectedType;
default:
return null;
}
case TypeCode.SByte:
switch (expectedType_)
{
case TypeCode.SByte:
case TypeCode.Int16:
case TypeCode.Int32:
case TypeCode.Int64:
case TypeCode.Single:
case TypeCode.Double:
case TypeCode.Decimal:
return expectedType;
default:
return null;
}
case TypeCode.Byte:
switch (expectedType_)
{
case TypeCode.Byte:
case TypeCode.Int16:
case TypeCode.UInt16:
case TypeCode.Int32:
case TypeCode.UInt32:
case TypeCode.Int64:
case TypeCode.UInt64:
case TypeCode.Single:
case TypeCode.Double:
case TypeCode.Decimal:
return expectedType;
default:
return null;
}
case TypeCode.Int16:
switch (expectedType_)
{
case TypeCode.Int16:
case TypeCode.Int32:
case TypeCode.Int64:
case TypeCode.Single:
case TypeCode.Double:
case TypeCode.Decimal:
return expectedType;
default:
return null;
}
case TypeCode.UInt16:
switch (expectedType_)
{
case TypeCode.UInt16:
case TypeCode.Int32:
case TypeCode.UInt32:
case TypeCode.Int64:
case TypeCode.UInt64:
case TypeCode.Single:
case TypeCode.Double:
case TypeCode.Decimal:
return expectedType;
default:
return null;
}
case TypeCode.Int32:
switch (expectedType_)
{
case TypeCode.Int32:
case TypeCode.Int64:
case TypeCode.Single:
case TypeCode.Double:
case TypeCode.Decimal:
return expectedType;
default:
return null;
}
case TypeCode.UInt32:
switch (expectedType_)
{
case TypeCode.UInt32:
case TypeCode.Int64:
case TypeCode.UInt64:
case TypeCode.Single:
case TypeCode.Double:
case TypeCode.Decimal:
return expectedType;
default:
return null;
}
case TypeCode.Int64:
switch (expectedType_)
{
case TypeCode.Int64:
case TypeCode.Single:
case TypeCode.Double:
case TypeCode.Decimal:
return expectedType;
default:
return null;
}
case TypeCode.UInt64:
switch (expectedType_)
{
case TypeCode.UInt64:
case TypeCode.Single:
case TypeCode.Double:
case TypeCode.Decimal:
return expectedType;
default:
return null;
}
case TypeCode.Single:
switch (expectedType_)
{
case TypeCode.Single:
case TypeCode.Double:
return expectedType;
default:
return null;
}
case TypeCode.Double:
switch (expectedType_)
{
case TypeCode.Char:
case TypeCode.SByte:
case TypeCode.Byte:
case TypeCode.Int16:
case TypeCode.UInt16:
case TypeCode.Int32:
case TypeCode.UInt32:
case TypeCode.Int64:
case TypeCode.UInt64:
case TypeCode.Single:
case TypeCode.Double:
case TypeCode.Decimal:
return expectedType;
default:
return null;
}
default:
return null;
}
}