예제 #1
0
        private void ProcessFields(Type type, SqlTable table)
        {
            var fields = type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);

            if (fields == null)
            {
                return;
            }

            foreach (var field in fields)
            {
                if (!field.IsDefined(typeof(ColumnAttribute), false))
                {
                    continue;
                }
                var columnAttribute = (ColumnAttribute)field.GetCustomAttributes(typeof(ColumnAttribute), false)[0];
                if (String.IsNullOrEmpty(columnAttribute.Name))
                {
                    columnAttribute.Name = field.Name;
                }

                var fieldBridge = new FieldBridge(field);
                var column      = new SqlColumn(table, columnAttribute.Name, fieldBridge)
                {
                    Alias         = String.IsNullOrEmpty(columnAttribute.Alias) ? field.Name : columnAttribute.Alias,
                    IsID          = field.IsDefined(typeof(IDAttribute), false),
                    IsPK          = field.IsDefined(typeof(PKAttribute), false),
                    IsOutPut      = field.IsDefined(typeof(OutPutAttribute), false),
                    IsReturnValue = field.IsDefined(typeof(RetrunValueAttribute), false),
                    Length        = columnAttribute.Length
                };

                table.Add(column);
            }
        }
예제 #2
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);
            }
        }