public ColumnAttribute Column(string memberName) { for (int i = 0; i < properties.Length; i++) { DynamicMember property = properties[i]; if (property.MemberInfo.Name.Equals(memberName)) { return(columns[i]); } } return(null); }
private static void ColumnInformation(out ColumnAttribute pkColumn, out DynamicMember pkProperty, out ColumnAttribute[] columns, out DynamicMember[] properties) { pkColumn = null; pkProperty = null; Type type = typeof(T); List <ColumnAttribute> columnList = new List <ColumnAttribute>(); List <DynamicMember> propertyList = new List <DynamicMember>(); BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public; foreach (PropertyInfo property in type.GetProperties(flags)) { foreach (object attr in property.GetCustomAttributes(typeof(ColumnAttribute), true)) { ColumnAttribute column = (ColumnAttribute)attr; object[] primaryKeyAttributes = property.GetCustomAttributes(typeof(IdAttribute), true); if (primaryKeyAttributes.Length > 0) { if (primaryKeyAttributes.Length > 1) { throw new ActiveRecordException(SR.GetString(SR.RowDataGateway_Duplicate_IdAttribute, new object[] { type.Name, primaryKeyAttributes.Length })); } pkColumn = column; pkProperty = new DynamicMember(type, property); } else { propertyList.Add(new DynamicMember(type, property)); columnList.Add(column); } } } foreach (FieldInfo field in type.GetFields(flags)) { foreach (object attr in field.GetCustomAttributes(typeof(ColumnAttribute), true)) { propertyList.Add(new DynamicMember(type, field)); columnList.Add((ColumnAttribute)attr); } } columns = columnList.ToArray(); properties = propertyList.ToArray(); if (pkProperty == null) { throw new NoPrimaryKeyAnnotationException( SR.GetString(SR.RowDataGateway_Incomplete_IdAttribute, new object[] { type.Name })); } if (pkColumn == null) { throw new NoColumnAttributeException( SR.GetString(SR.RowDataGateway_Incomplete_IdAttribute, new object[] { type.Name, pkProperty.MemberInfo.Name })); } }
private static void BindColumn(T item, DbCommand command, ColumnAttribute column, DynamicMember property) { BindColumn(command, column, property.Get(item)); }
private static void MarshallProperty(T item, IDataRecord reader, ColumnAttribute column, DynamicMember property) { if (reader[column.Name].Equals(DBNull.Value)) { if (column.Nullable) { property.Set(item, null); } else { throw new ArgumentNullException(SR.GetString(SR.RowDataGateway_Null_Property, new object[] { property.MemberInfo.Name })); } } else { property.Set(item, reader[column.Name]); } }
public RowDataGatewayBinding(ColumnAttribute column, DynamicMember member, object value) { this.column = column; this.member = member; this.value = value; }