internal static Type ConvertNumericTypeForAlithmetics(Type type, Boolean needsSigned)
{
var isNullable = Nullable.GetUnderlyingType(type) != null;
switch (Type.GetTypeCode(isNullable ? Nullable.GetUnderlyingType(type) : type))
{
case TypeCode.Char:
case TypeCode.SByte:
case TypeCode.Byte:
case TypeCode.Int16:
case TypeCode.UInt16:
case TypeCode.Int32:
return isNullable
? typeof(Nullable<Int32>)
: typeof(Int32);
case TypeCode.UInt32:
return needsSigned
? isNullable
? typeof(Nullable<Int64>)
: typeof(Int64)
: isNullable
? typeof(Nullable<UInt32>)
: typeof(UInt32);
case TypeCode.Int64:
return isNullable
? typeof(Nullable<Int64>)
: typeof(Int64);
case TypeCode.UInt64:
return needsSigned
? null
: isNullable
? typeof(Nullable<UInt64>)
: typeof(UInt64);
default:
return null;
}
}