Example #1
0
        internal static SqlUdtInfo TryGetFromType([NotNull] Type target)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            if (_types2UdtInfo == null)
            {
                _types2UdtInfo = new Dictionary <Type, SqlUdtInfo>();
            }
            SqlUdtInfo sqlUdtInfo;

            if (!_types2UdtInfo.TryGetValue(target, out sqlUdtInfo))
            {
                object[] customAttributes = target.GetCustomAttributes(typeof(SqlUserDefinedTypeAttribute), false);
                if (customAttributes.Length == 1)
                {
                    // ReSharper disable once AssignNullToNotNullAttribute
                    sqlUdtInfo = new SqlUdtInfo((SqlUserDefinedTypeAttribute)customAttributes[0]);
                }
                _types2UdtInfo.Add(target, sqlUdtInfo);
            }

            Debug.Assert(sqlUdtInfo != null);
            return(sqlUdtInfo);
        }
Example #2
0
        internal static SqlUdtInfo GetFromType([NotNull] Type target)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            SqlUdtInfo fromType = TryGetFromType(target);

            if (fromType == null)
            {
                throw new InvalidOperationException();
            }
            return(fromType);
        }
Example #3
0
        internal static SqlUdtInfo TryGetFromType([NotNull] Type target)
        {
            if (target == null) throw new ArgumentNullException("target");

            if (_types2UdtInfo == null)
                _types2UdtInfo = new Dictionary<Type, SqlUdtInfo>();
            SqlUdtInfo sqlUdtInfo;
            if (!_types2UdtInfo.TryGetValue(target, out sqlUdtInfo))
            {
                object[] customAttributes = target.GetCustomAttributes(typeof(SqlUserDefinedTypeAttribute), false);
                if (customAttributes.Length == 1)
                    // ReSharper disable once AssignNullToNotNullAttribute
                    sqlUdtInfo = new SqlUdtInfo((SqlUserDefinedTypeAttribute)customAttributes[0]);
                _types2UdtInfo.Add(target, sqlUdtInfo);
            }

            Debug.Assert(sqlUdtInfo != null);
            return sqlUdtInfo;
        }