Example #1
0
 public PropertyDescriptor(string name, GenerateByAttribute generateBy, KeyAttribute keyAttribute, Type clrType, ColumnTypeAttribute columnType)
 {
     Name       = name;
     GenerateBy = generateBy;
     Key        = keyAttribute;
     ClrType    = clrType;
     ColumnType = columnType;
 }
Example #2
0
        internal MapperBase GetMapper(Type propertyType, ColumnTypeAttribute columnType = null)
        {
            var mapper = TryGetMapper(propertyType, columnType);

            if (mapper == null)
            {
                if (columnType == null)
                {
                    columnType = GetDefaultColumnType(propertyType);
                }
                throw new Exception(string.Format("Mapper not found: {0} <-> {1}", propertyType, columnType));
            }
            return(mapper);
        }
Example #3
0
 private void AsignColTypeAttrToDef(ColumnFieldDefinition colunmF,
                                    ColumnTypeAttribute colTypeAttr, PropertyInfo prop)
 {
     if (colTypeAttr != null)
     {
         colunmF.PropName  = prop.Name;
         colunmF.FieldType = colTypeAttr.DBType;
         colunmF.Length    = colTypeAttr.Length;
         colunmF.Nullable  = colTypeAttr.Nullable;
         colunmF.Comment   = colTypeAttr.Comment;
     }
     else
     {
         colunmF.PropName  = prop.Name;
         colunmF.FieldType = Dapper.SqlMapper.LookupDbType(prop.PropertyType, prop.Name);
     }
 }
Example #4
0
        internal MapperBase TryGetMapper(Type propertyType, ColumnTypeAttribute columnType = null)
        {
            if (IsEnum(propertyType))
            {
                propertyType = typeof(Enum);
            }
            if (columnType == null)
            {
                if (!_defaultTypeAttributes.ContainsKey(propertyType))
                {
                    return(null);
                }
                columnType = _defaultTypeAttributes[propertyType];
            }
            var key = new KeyValuePair <Type, ColumnTypeAttribute>(propertyType, columnType);

            return(_mappers.ContainsKey(key) ? _mappers[key] : null);
        }
Example #5
0
        private ColumnFieldDefinition GetColumnFieldDefByProprty(PropertyInfo prop)
        {
            object[]            attrs       = prop.GetCustomAttributes(true);
            var                 ret         = new ColumnFieldDefinition();
            ColumnNameAttribute colNameAttr = null;
            ColumnTypeAttribute colTypeAttr = null;

            foreach (object attr in attrs)
            {
                if (attr.GetType().Equals(typeof(ColumnNameAttribute)))
                {
                    colNameAttr = attr as ColumnNameAttribute;
                }
                if (attr.GetType().Equals(typeof(ColumnTypeAttribute)))
                {
                    colTypeAttr = attr as ColumnTypeAttribute;
                }
            }
            AsignColNameAttrToDef(ret, colNameAttr, prop);
            AsignColTypeAttrToDef(ret, colTypeAttr, prop);
            return(ret);
        }
 public ConvertExpression(ColumnTypeAttribute toType, ColumnExpression column, Type type) : base(ExpressionType.Default, type)
 {
     ToType = toType;
     Column = column;
 }
Example #7
0
 public MapperBase(Type propertyType, ColumnTypeAttribute columnType)
 {
     PropertyType = propertyType;
     ColumnType   = columnType;
 }