private static SqlColumnType _getSqlType(MemberInfo mi) { // See if there's any SqlTypeAttribute on the mi // If so, pull the info from there. var att = mi.GetCustomAttributes(typeof(SqlTypeAttribute), true) .FirstOr(new SqlTypeAttribute()) as SqlTypeAttribute; var baseType = SqlTypeConversion.GetSqlType(mi.ReturnType()); // For anything that's missing, get the assumed type info var res = new SqlColumnType( att.Type ?? baseType.SqlType, att.IsNullable ?? baseType.IsNullable, att.Length ?? baseType.Length, att.Precision ?? baseType.Precision, att.Scale ?? baseType.Scale); return res; }
/// <summary> /// Convert to the equivalent .NET type /// </summary> /// <param name="sqlTypeName"></param> /// <returns></returns> public static Type GetDotNetType(SqlColumnType ct) { var mapped = _toCMappings.Where(kv => kv.Key.SqlType == ct.SqlType && kv.Key.IsNullable == ct.IsNullable); if (!mapped.Any()) throw new NotImplementedException("Don't know how to convert SqlColumnType '" + ct.Print() + "' to a .Net type"); return mapped.First().Value; }