static private GetStorageType ( |
||
dataType | ||
return | StorageType |
internal static StorageType GetStorageType(Type dataType)
{
for (int i = 0; i < s_storageClassType.Length; ++i)
{
if (dataType == s_storageClassType[i])
{
return (StorageType)i;
}
}
TypeCode tcode = Type.GetTypeCode(dataType);
if (TypeCode.Object != tcode)
{ // enum -> Int64/Int32/Int16/Byte
return (StorageType)tcode;
}
return StorageType.Empty;
}
public static SqlInt32 ConvertToSqlInt32(object value) { if (value == DBNull.Value) { return(SqlInt32.Null); } Type type = value.GetType(); switch (DataStorage.GetStorageType(type)) { case StorageType.Byte: return((SqlInt32)((byte)value)); case StorageType.Int16: return((SqlInt32)((short)value)); case StorageType.UInt16: return((SqlInt32)((ushort)value)); case StorageType.Int32: return((int)value); case StorageType.SqlByte: return((SqlByte)value); case StorageType.SqlInt16: return((SqlInt16)value); case StorageType.SqlInt32: return((SqlInt32)value); } throw ExceptionBuilder.ConvertFailed(type, typeof(SqlInt32)); }