Ejemplo n.º 1
0
        private IMap MatchProperty(DeconstructedProperty to, IEnumerable<PropertyInfo> fromProperties, IMap map = null)
        {
            var index = 0;
            var current = "";
            foreach (var token in to.RemainingNameTokens)
            {
                current += token;
                index += 1;
                var match = fromProperties.FirstOrDefault(x => x.Name.ToLower() == current.ToLower());
                if (match.IsNotNull())
                {
                    if (map.IsNull())
                        map = new Map(match, to.OriginalPropertyInfo);
                    else
                    {
                        if (to.RemainingNameTokens.Any())
                            map.FromComponents.Add(match);

                    }

                    to.RemainingNameTokens = to.RemainingNameTokens.Skip(index).ToArray();
                    map = MatchProperty(to, match.PropertyType.GetProperties(), map);
                }
            }

            if (map.IsNotNull() && map.FromComponents.Last().PropertyType != map.ToComponents.Last().PropertyType
                &&
                !((map.ToComponents.Last().PropertyType.IsGenericType &&
                  map.ToComponents.Last().PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
                 &&
                 map.ToComponents.Last().PropertyType.GetGenericArguments()[0] == map.FromComponents.Last().PropertyType))
            {
                return null;
            }

            return map;
        }