internal ClassMetadata(TypeInfo typeInfo) { m_TypeInfo = typeInfo; #if !DataAnnotations_Missing var table = (TableAttribute)typeInfo.GetCustomAttributes(typeof(TableAttribute), true).SingleOrDefault(); if (table != null) { MappedTableName = table.Name; MappedSchemaName = table.Schema; } #endif #if Weird_Reflection var shadowingProperties = (from p in typeInfo.DeclaredProperties where IsHidingMember(p) select p).ToList(); var propertyList = typeInfo.DeclaredProperties.ToList(); #elif TypeInfo_Is_Not_Type var type = typeInfo.AsType(); var shadowingProperties = (from p in type.GetProperties() where IsHidingMember(p) select p).ToList(); var propertyList = type.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); #else var shadowingProperties = (from p in typeInfo.GetProperties() where IsHidingMember(p) select p).ToList(); var propertyList = typeInfo.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); #endif Func <PropertyInfo, bool> IsHidden = propertyInfo => !shadowingProperties.Contains(propertyInfo) && shadowingProperties.Any(p => p.Name == propertyInfo.Name); Properties = new PropertyMetadataCollection(propertyList.Where(p => !IsHidden(p)).Select(p => new PropertyMetadata(p))); //List the properties that are affected when the indicated property is modified. foreach (var property in Properties) { foreach (CalculatedFieldAttribute fieldList in property.PropertyInfo.GetCustomAttributes(typeof(CalculatedFieldAttribute), true)) { foreach (var field in fieldList.SourceProperties) { if (!Properties.Contains(field)) { throw new InvalidOperationException(string.Format("Cannot find property {0} on type {1}. This is needed for the calculated property {2}", field, typeInfo.FullName, property.Name)); } Properties[field].AddCalculatedField(property); } } } foreach (var property in Properties) { property.EndInit(); } Constructors = new ConstructorMetadataCollection(typeInfo.DeclaredConstructors); }
internal ClassMetadata(TypeInfo typeInfo) { TypeInfo = typeInfo; var table = (TableAttribute)typeInfo.GetCustomAttributes(typeof(TableAttribute), true).SingleOrDefault(); if (table != null) { MappedTableName = table.Name; MappedSchemaName = table.Schema; } var shadowingProperties = (from p in typeInfo.GetProperties() where IsHidingMember(p) select p).ToList(); var propertyList = typeInfo.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); bool IsHidden(PropertyInfo propertyInfo) => !shadowingProperties.Contains(propertyInfo) && shadowingProperties.Any(p => string.CompareOrdinal(p.Name, propertyInfo.Name) == 0); Properties = new PropertyMetadataCollection(propertyList.Where(p => !IsHidden(p)).Select(p => new PropertyMetadata(p))); //List the properties that are affected when the indicated property is modified. foreach (var property in Properties) { foreach (CalculatedFieldAttribute fieldList in property.PropertyInfo.GetCustomAttributes(typeof(CalculatedFieldAttribute), true)) { foreach (var field in fieldList.SourceProperties) { if (!Properties.Contains(field)) { throw new InvalidOperationException($"Cannot find property {field} on type {typeInfo.FullName}. This is needed for the calculated property {property.Name}"); } Properties[field].AddCalculatedField(property); } } } foreach (var property in Properties) { property.EndInit(); } Constructors = new ConstructorMetadataCollection(typeInfo.DeclaredConstructors); }