public void FindPublicPropertyWithAttributes() { IList result = Reflector.FindMembers(Reflector.InstanceCriteria, typeof(GuidHolder), false, typeof(TableColumnAttribute), typeof(PrimaryKeyAttribute)); Assert.AreEqual(2, result.Count, "Did not locate all public properties with TableColumn attribute."); MemberAttributeInfo mai = (MemberAttributeInfo)result[0]; Assert.IsNotNull(mai.Attributes, "Did not locate any attributes."); Assert.AreEqual(2, mai.Attributes.Count, "Did not locate both attributes on first member."); }
/// <summary> /// Constructor for fields using information obtained from the TableColumn attribute. /// </summary> public FieldMap(ObjectMap map, MemberAttributeInfo memberAttributeInfo) { this.map = map; memberInfo = memberAttributeInfo.MemberInfo; if (memberInfo is PropertyInfo) { memberType = (memberInfo as PropertyInfo).PropertyType; } else { memberType = (memberInfo as FieldInfo).FieldType; } // extract information from attributes if (memberAttributeInfo.Attributes != null) { foreach (Attribute attr in memberAttributeInfo.Attributes) { if (attr is TableColumnAttribute) { TableColumnAttribute tc = attr as TableColumnAttribute; SetColumnName(tc.Name ?? memberInfo.Name); SetNullValue(tc.NullValue); SetIsNullable(!tc.NotNull); SetSize(tc.Size); if (tc.HasDbType) { SetDbType(tc.DatabaseType); } else { SetDbType(NO_DBTYPE); } handleEnumAsString = tc.HandleEnumAsString; isReadOnly = tc.IsReadOnly; isUpdateAfterWrite = tc.IsUpdateAfterWrite; } else if (attr is PrimaryKeyAttribute) { PrimaryKeyAttribute pk = attr as PrimaryKeyAttribute; SetIsPrimaryKey(true); SetIsAutoGenerated(pk.AutoGenerated); if (IsAutoGenerated) { map.IdentityMap = this; } } else if (attr is ForeignKeyAttribute) { ForeignKeyAttribute fk = attr as ForeignKeyAttribute; SetForeignKeyTableName(fk.ForeignTable); SetForeignKeyColumnName(fk.ForeignColumn); } else if (attr is ConcurrencyAttribute) { ConcurrencyAttribute ca = attr as ConcurrencyAttribute; Check.Verify(memberType == typeof(int) || memberType == typeof(long), Error.DeveloperError, "Unsupported property type {0} for ConcurrencyAttribute {1}", memberInfo.ReflectedType, memberInfo.Name); isConcurrencyColumn = true; map.ConcurrencyMap = this; } else if (attr is SoftDeleteAttribute) { SoftDeleteAttribute sd = attr as SoftDeleteAttribute; Check.Verify(memberType == typeof(int) || memberType == typeof(long), Error.DeveloperError, "Unsupported property type {0} for SoftDeleteAttribute {1}", memberInfo.ReflectedType, memberInfo.Name); isSoftDeleteColumn = true; map.SoftDeleteMap = this; } else if (attr is SequenceNameAttribute) { // sequence name used when available (in place of name conventions or autodetected value) sequenceName = (attr as SequenceNameAttribute).Name; } else if (attr is InheritanceAttribute) { // sequence name used when available (in place of name conventions or autodetected value) map.InheritanceMap = this; } } } }