/// <summary> /// Constructs a TableMap instance for the current table, including inherited columns down to the specified class /// </summary> /// <param name="includePropertiesAssignableTo">The lowest class that properties should be included from</param> public TableMap(Type includePropertiesAssignableTo) { Table(TableName = ModelType.Name); //--'TableName = ' is a slight hack to get the compiler to stop yelling about it not being set, even though Table(...) would have set it or thrown an exception if (includePropertiesAssignableTo.IsInterface || !includePropertiesAssignableTo.IsAssignableFrom(ModelType)) { throw new ArgumentException($"The type '{includePropertiesAssignableTo.FullName}' is not a subclass of '{ModelType.FullName}'."); } _includePropertiesAssignableTo = includePropertiesAssignableTo; //--Keep track of what properties' orders are within the class, as TableMapBuilders aren't applied in any specific order _propertyOrder = ModelType.GetProperties(BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.NonPublic) .Indexed() .ToDictionary(x => x.item, x => x.index); TypeColumns = new ReadOnlyDictionary <Type, Dictionary <PropertyInfo, IColumnMap> >(ModelType.GetBaseTypes(includeSeed: true, includeInterfaces: true).Distinct() .ToDictionary(t => t, t => new Dictionary <PropertyInfo, IColumnMap>())); foreach (var mapBuilder in TableMapSource.GetTableMapBuilders <T>()) { //--I really hate having to do this... mapBuilder.GetType() .GetMethod(nameof(TableMapBuilder <object> .Map)) .MakeGenericMethod(ModelType) .Invoke(mapBuilder, new[] { this }); } }
static ColumnValueProvider() { _tableMapBuilders = RetrievalDictionary.Build((Type type) => TableMapSource.GetTableMapBuilders(type)); }