public void MapContext(IDapperContext dapperContext = null) { if (dapperContext == null) { dapperContext = this; } var suffixAttribute = GetType().GetCustomAttribute <SuffixAttribute>(); var tableSuffix = suffixAttribute?.Suffix; var properties = GetProperties(dapperContext.GetType()); foreach (var property in properties) { var propertyType = property.PropertyType; var propertyGenericType = propertyType.GenericTypeArguments; var a = typeof(Mapping <>); var gA = a.MakeGenericType(propertyGenericType); var b = typeof(IMapping <>); var gB = b.MakeGenericType(propertyGenericType); if (propertyType != gB) { continue; } var mappings = propertyGenericType[0].GetCustomAttribute <TableAttribute>(); var tableName = mappings?.Name ?? property.Name; var schema = mappings?.Schema ?? "dbo"; tableName = $"{tableSuffix}{tableName}"; property.SetValue(dapperContext, Activator.CreateInstance(gA, _formatProvider, _connection, schema, tableName)); } }