private void FindInherited(Type type, LitTable table) { if (type.IsDefined(typeof(MapAttribute), false)) { object[] attrs = type.GetCustomAttributes(typeof(MapAttribute), false); foreach (MapAttribute attr in attrs) { IDataBridge data = null; BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; MemberInfo member = type.GetProperty(attr.Field, flags); if (member != null) { data = new PropertyBridge((PropertyInfo)member); } else { member = type.GetField(attr.Field, flags); if (member != null) data = new FieldBridge((FieldInfo)member); else throw new LightException("member " + attr.Field + " not found in class " + type.Name); } if (attr.Name == null || attr.Name.Length == 0) attr.Name = member.Name; SqlColumn column = new SqlColumn(table, attr.Name, data); if (attr.Alias == null || attr.Alias.Length == 0) column.Alias = attr.Field; else column.Alias = attr.Alias; column.IsID = attr.ID; column.IsPK = attr.PK; table.Add(column); } } }
public virtual void Add(SqlColumn column) { if (column.IsID) { if (identity != null) { throw new LightException(string.Format( "cannot add idenity column {0} to table {1}, it already has an identity column {2}", column.Name, this.Name, identity.Name)); } identity = column; } columns.Add(column); column.Ordinal = columns.Count; }
private void ProcessProperties(Type type, LitTable table) { PropertyInfo[] fields = type.GetProperties( BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); foreach (PropertyInfo field in fields) { if (!field.IsDefined(typeof(ColumnAttribute), false)) continue; ColumnAttribute colAttr = (ColumnAttribute) field.GetCustomAttributes(typeof(ColumnAttribute), false)[0]; PropertyBridge data = new PropertyBridge(field); if (colAttr.Name == null || colAttr.Name.Length == 0) colAttr.Name = field.Name; SqlColumn column = new SqlColumn(table, colAttr.Name, data); if (colAttr.Alias == null || colAttr.Alias.Length == 0) column.Alias = field.Name; else column.Alias = colAttr.Alias; if (field.IsDefined(typeof(IDAttribute), false)) column.IsID = true; if (field.IsDefined(typeof(PKAttribute), false)) column.IsPK = true; table.Add(column); } }