private static PropertyInfo GetPropertyInfo(Type type, string columnName) { string cacheKey = string.Format("{0};{1}", type.FullName, columnName); PropertyInfo info; if (TypePropertyMapCache.TryGetValue(cacheKey, out info)) { return(info); } IEntityMap entityMap; if (FluentMapper.EntityMaps.TryGetValue(type, out entityMap)) { var propertyMaps = entityMap.PropertyMaps; // Find the mapping for the column name. var propertyMap = propertyMaps.FirstOrDefault(m => MatchColumnNames(m, columnName)); if (propertyMap != null) { if (!propertyMap.Ignored) { TypePropertyMapCache.Add(cacheKey, propertyMap.PropertyInfo); return(propertyMap.PropertyInfo); } } } // If we get here, the property was not mapped. TypePropertyMapCache.Add(cacheKey, null); return(null); }
private static PropertyInfo GetPropertyInfo(Type type, string columnName) { var cacheKey = $"{type.FullName};{columnName}"; if (TypePropertyMapCache.TryGetValue(cacheKey, out var info)) { return(info); } if (FluentMapper.TypeConventions.TryGetValue(type, out var conventions)) { foreach (var convention in conventions) { // Find property map for current type and column name. var maps = convention.PropertyMaps #if NETSTANDARD1_3 // HACK: ReflectedType isn't available on.NET Standard 1.3, // this will cause issues when mapping derived entities. .Where(map => map.PropertyInfo.DeclaringType == type && MatchColumnNames(map, columnName)) #else .Where(map => map.PropertyInfo.ReflectedType == type && MatchColumnNames(map, columnName)) #endif .ToList(); if (maps.Count > 1) { const string msg = "Finding mappings for column '{0}' yielded more than 1 PropertyMap. The conventions should be more specific. Type: '{1}'. Convention: '{2}'."; throw new Exception(string.Format(msg, columnName, type, convention)); } if (maps.Count == 0) { // This convention has no property maps, continue to next convention. continue; } info = maps[0].PropertyInfo; TypePropertyMapCache.TryAdd(cacheKey, info); return(info); } } // If we get here, the property was not mapped. TypePropertyMapCache.TryAdd(cacheKey, null); return(null); }
private static PropertyInfo GetPropertyInfo(Type type, string columnName) { var cacheKey = $"{type.FullName};{columnName}"; PropertyInfo info; if (TypePropertyMapCache.TryGetValue(cacheKey, out info)) { return(info); } IList <Convention> conventions; if (FluentMapper.TypeConventions.TryGetValue(type, out conventions)) { foreach (var convention in conventions) { // Find property map for current type and column name. // todo: ReflectedType is unavailable on CoreFX var maps = convention.PropertyMaps .Where(map => map.PropertyInfo.DeclaringType == type && MatchColumnNames(map, columnName)) .ToList(); if (maps.Count > 1) { const string msg = "Finding mappings for column '{0}' yielded more than 1 PropertyMap. The conventions should be more specific. Type: '{1}'. Convention: '{2}'."; throw new Exception(string.Format(msg, columnName, type, convention)); } if (maps.Count == 0) { // This convention has no property maps, continue to next convention. continue; } info = maps[0].PropertyInfo; TypePropertyMapCache.TryAdd(cacheKey, info); return(info); } } // If we get here, the property was not mapped. TypePropertyMapCache.TryAdd(cacheKey, null); return(null); }
private static PropertyInfo GetPropertyInfo(Type type, string columnName) { var cacheKey = $"{type.FullName};{columnName}"; PropertyInfo info; if (TypePropertyMapCache.TryGetValue(cacheKey, out info)) { return(info); } IEntityMap entityMap; if (FluentMapper.EntityMaps.TryGetValue(type, out entityMap)) { var propertyMaps = entityMap.PropertyMaps; // Find the mapping for the column name. var propertyMap = propertyMaps.FirstOrDefault(m => MatchColumnNames(m, columnName)); if (propertyMap != null) { if (!propertyMap.Ignored) { TypePropertyMapCache.TryAdd(cacheKey, propertyMap.PropertyInfo); return(propertyMap.PropertyInfo); } #if !NETSTANDARD1_3 else { var ignoredPropertyInfo = new IgnoredPropertyInfo(); TypePropertyMapCache.TryAdd(cacheKey, ignoredPropertyInfo); return(ignoredPropertyInfo); } #endif } } // If we get here, the property was not mapped. TypePropertyMapCache.TryAdd(cacheKey, null); return(null); }