System.Data.Common.DataStorage.GetStorageType C# (CSharp) Méthode

GetStorageType() static private méthode

static private GetStorageType ( Type dataType ) : StorageType
dataType System.Type
Résultat 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;
        }

Usage Example

        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));
        }
All Usage Examples Of System.Data.Common.DataStorage::GetStorageType