Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
            }

            IList <Convention> conventions;

            if (FluentMapper.TypeConventions.TryGetValue(type, out conventions))
            {
                foreach (var convention in conventions)
                {
                    // Find property map for current type and column name.
                    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.Add(cacheKey, info);
                    return(info);
                }
            }

            // If we get here, the property was not mapped.
            TypePropertyMapCache.Add(cacheKey, null);
            return(null);
        }