public void Should_Convert_Basic_Member_Access() { var map = new Map(ForType<Entity>.GetProperty(x=>x.Name) , ForType<Model>.GetProperty(x=>x.name)); Expression<Func<Model, bool>> exp = x => x.name=="George Michaels" ; Func<Entity,bool> converted = Converter<Entity>.Convert(exp,new IMap[]{map}).Compile(); converted(_entity).ShouldBeTrue(); }
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; }