Пример #1
0
        private void ProcessMaps(Type type, SqlTable table)
        {
            if (!type.IsDefined(typeof(MapAttribute), false))
            {
                return;
            }
            var attributes = type.GetCustomAttributes(typeof(MapAttribute), false);

            foreach (MapAttribute attribute in attributes)
            {
                IDataBridge dataBridge;
                var         flags  = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
                MemberInfo  member = type.GetProperty(attribute.Field, flags);

                if (member != null)
                {
                    dataBridge = new PropertyBridge((PropertyInfo)member);
                }
                else
                {
                    member = type.GetField(attribute.Field, flags);

                    if (member != null)
                    {
                        dataBridge = new FieldBridge((FieldInfo)member);
                    }
                    else
                    {
                        throw new DalException(String.Format("Member {0} not found in class {1}", attribute.Field, type.Name));
                    }
                }

                if (String.IsNullOrEmpty(attribute.Name))
                {
                    attribute.Name = member.Name;
                }

                var column = new SqlColumn(table, attribute.Name, dataBridge)
                {
                    Alias         = String.IsNullOrEmpty(attribute.Alias) ? attribute.Field : attribute.Alias,
                    IsID          = attribute.ID,
                    IsPK          = attribute.PK,
                    IsOutPut      = attribute.OutPut,
                    IsReturnValue = attribute.ReturnValue,
                    Length        = attribute.Length
                };

                table.Add(column);
            }
        }
Пример #2
0
        private void ProcessProperties(Type type, SqlTable table)
        {
            var properties = type.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);

            if (properties == null)
            {
                return;
            }

            foreach (var property in properties)
            {
                if (!property.IsDefined(typeof(ColumnAttribute), false))
                {
                    continue;
                }

                var columnAttribute = (ColumnAttribute)property.GetCustomAttributes(typeof(ColumnAttribute), false)[0];
                if (String.IsNullOrEmpty(columnAttribute.Name))
                {
                    columnAttribute.Name = property.Name;
                }

                var propertyBridge = new PropertyBridge(property);
                var column         = new SqlColumn(table, columnAttribute.Name, propertyBridge)
                {
                    Alias         = String.IsNullOrEmpty(columnAttribute.Alias) ? property.Name : columnAttribute.Alias,
                    ColumnType    = columnAttribute.NullableColumnType,
                    DefaultValue  = columnAttribute.DefaultValue,
                    IsID          = property.IsDefined(typeof(IDAttribute), false),
                    IsPK          = property.IsDefined(typeof(PKAttribute), false),
                    IsOutPut      = property.IsDefined(typeof(OutPutAttribute), false),
                    IsReturnValue = property.IsDefined(typeof(RetrunValueAttribute), false),
                    IsVersionLock = property.IsDefined(typeof(VersionLockAttribute), false),
                    IsIgnored     = property.IsDefined(typeof(IgnoredAttribute), false),
                    Length        = columnAttribute.Length
                };

                if (property.IsDefined(typeof(DateTimeLockAttribute), false))
                {
                    var datetimeAttribute = (DateTimeLockAttribute)property.GetCustomAttributes(typeof(DateTimeLockAttribute), false)[0];
                    column.IsTimestampLock     = true;
                    column.TimestampExpression = datetimeAttribute.Expression;
                }

                table.Add(column);
            }
        }