Beispiel #1
0
        internal static SqlUdtInfo GetFromType(Type target)
        {
            SqlUdtInfo info = TryGetFromType(target);

            if (info == null)
            {
                return(null);
            }
            return(info);
        }
Beispiel #2
0
        internal static SqlUdtInfo TryGetFromType(Type target)
        {
            SqlUdtInfo info = null;

            object[] customAttributes = target.GetCustomAttributes(typeof(SqlUserDefinedTypeAttribute), false);
            if ((customAttributes != null) && (customAttributes.Length == 1))
            {
                info = new SqlUdtInfo((SqlUserDefinedTypeAttribute)customAttributes[0]);
            }
            return(info);
        }
Beispiel #3
0
        private static MetaType GetMetaTypeFromValue(Type dataType, object value, bool inferLen)
        {
            switch (Type.GetTypeCode(dataType))
            {
            case TypeCode.Empty:
                return(null);

            case TypeCode.Object:
                if (dataType != typeof(byte[]))
                {
                    if (dataType == typeof(Guid))
                    {
                        return(MetaUniqueId);
                    }
                    if (dataType == typeof(object))
                    {
                        return(MetaVariant);
                    }
                    if (dataType == typeof(SqlBinary))
                    {
                        return(MetaVarBinary);
                    }
                    if (dataType == typeof(SqlBoolean))
                    {
                        return(MetaBit);
                    }
                    if (dataType == typeof(SqlByte))
                    {
                        return(MetaTinyInt);
                    }
                    if (dataType == typeof(SqlBytes))
                    {
                        return(MetaVarBinary);
                    }
                    if (dataType != typeof(SqlChars))
                    {
                        if (dataType == typeof(SqlDateTime))
                        {
                            return(MetaDateTime);
                        }
                        if (dataType == typeof(SqlDouble))
                        {
                            return(MetaFloat);
                        }
                        if (dataType == typeof(SqlGuid))
                        {
                            return(MetaUniqueId);
                        }
                        if (dataType == typeof(SqlInt16))
                        {
                            return(MetaSmallInt);
                        }
                        if (dataType == typeof(SqlInt32))
                        {
                            return(MetaInt);
                        }
                        if (dataType == typeof(SqlInt64))
                        {
                            return(MetaBigInt);
                        }
                        if (dataType == typeof(SqlMoney))
                        {
                            return(MetaMoney);
                        }
                        if (dataType == typeof(SqlDecimal))
                        {
                            return(MetaDecimal);
                        }
                        if (dataType == typeof(SqlSingle))
                        {
                            return(MetaReal);
                        }
                        if (dataType == typeof(SqlXml))
                        {
                            return(MetaXml);
                        }
                        if (dataType == typeof(XmlReader))
                        {
                            return(MetaXml);
                        }
                        if (dataType != typeof(SqlString))
                        {
                            if ((dataType == typeof(IEnumerable <DbDataRecord>)) || (dataType == typeof(DataTable)))
                            {
                                return(MetaTable);
                            }
                            if (dataType == typeof(TimeSpan))
                            {
                                return(MetaTime);
                            }
                            if (dataType == typeof(DateTimeOffset))
                            {
                                return(MetaDateTimeOffset);
                            }
                            if (SqlUdtInfo.TryGetFromType(dataType) == null)
                            {
                                return(null);
                            }
                            return(MetaUdt);
                        }
                        if (inferLen)
                        {
                            SqlString str2 = (SqlString)value;
                            if (!str2.IsNull)
                            {
                                SqlString str = (SqlString)value;
                                return(PromoteStringType(str.Value));
                            }
                        }
                    }
                    return(MetaNVarChar);
                }
                if (inferLen && (((byte[])value).Length > 0x1f40))
                {
                    return(MetaImage);
                }
                return(MetaVarBinary);

            case TypeCode.DBNull:
                return(null);

            case TypeCode.Boolean:
                return(MetaBit);

            case TypeCode.Char:
                return(null);

            case TypeCode.SByte:
                return(null);

            case TypeCode.Byte:
                return(MetaTinyInt);

            case TypeCode.Int16:
                return(MetaSmallInt);

            case TypeCode.UInt16:
                return(null);

            case TypeCode.Int32:
                return(MetaInt);

            case TypeCode.UInt32:
                return(null);

            case TypeCode.Int64:
                return(MetaBigInt);

            case TypeCode.UInt64:
                return(null);

            case TypeCode.Single:
                return(MetaReal);

            case TypeCode.Double:
                return(MetaFloat);

            case TypeCode.Decimal:
                return(MetaDecimal);

            case TypeCode.DateTime:
                return(MetaDateTime);

            case TypeCode.String:
                if (!inferLen)
                {
                    return(MetaNVarChar);
                }
                return(PromoteStringType((string)value));
            }
            return(null);
        }