public IRootAccessor <TClass> MapProperties <TProperty>(Expression <Func <TClass, TProperty> > expr, Expression <Func <TProperty, bool> > includeFilter = null) where TProperty : class { Visit(expr); var accessor = latestAccessor as IPropertyAccessor <TClass>; //dupes at this point if (!_rootAccessor.Properties.Contains(accessor)) { _rootAccessor.Properties.Add(accessor); } if (includeFilter != null) { if (latestAccessor is PropertyAccessor <TClass, TProperty> accessorImpl) { accessorImpl.AddFilter(includeFilter); } else { //can type checking be added here? var propertyAccessor = _rootAccessor.GetByPath(PathWalker.GetPath(expr)); dynamic dynamicAccessor = propertyAccessor; AddFilterForDynamicType(dynamicAccessor, includeFilter); } } return(_rootAccessor); }
internal static List <MemberInfo> GetMembers(MemberExpression expr) { var walker = new PathWalker(); walker.Visit(expr); walker._members.Reverse(); return(walker._members); }
internal static List <string> GetPath(MemberExpression expr) { var walker = new PathWalker(); walker.Visit(expr); walker._members.Reverse(); return(walker._members.Select(x => x.Name).ToList()); }
internal static List <MemberInfo> GetMembers <TEntity, TProperty>(Expression <Func <TEntity, TProperty> > expr) where TEntity : class where TProperty : class { var walker = new PathWalker(); walker.Visit(expr); walker._members.Reverse(); return(walker._members); }
internal static List <string> GetPath <TEntity, TProperty>(Expression <Func <TEntity, TProperty> > expr) where TEntity : class where TProperty : class { var walker = new PathWalker(); walker.Visit(expr); walker._members.Reverse(); return(walker._members.Select(x => x.Name).ToList()); }
internal static PropertyAccessor <TEntity, TProperty> Create <TEntity, TProperty> (MemberExpression exp, IPropertyAccessor parentAccessor, IRootAccessor root) where TEntity : class where TProperty : class { var pathParts = PathWalker.GetPath(exp); var newAccessor = root.GetByPath <TEntity, TProperty>(pathParts) ?? new PropertyAccessor <TEntity, TProperty>(exp, root.MappingSchema); if (parentAccessor != null && !newAccessor.Properties.Contains(parentAccessor)) { var genericParentAccessor = (IPropertyAccessor <TProperty>)parentAccessor; newAccessor.PropertiesOfTClass.Add(genericParentAccessor); } return(newAccessor); }
public static bool Set <TClass, TProperty>(Expression <Func <TClass, TProperty> > expr, Func <IQueryable <TClass>, Expression <Func <TProperty, bool> >, List <TProperty> > queryExecuter, Func <IQueryable <TClass>, Expression <Func <TProperty, bool> >, IQueryable <TProperty> > reusableQueryBuilder) where TClass : class where TProperty : class { var memberInfo = PathWalker.GetMembers(expr).LastOrDefault(); if (memberInfo == null) { return(false); } var cpa = new CustomPropertyAccessor <TClass, TProperty>( memberInfo.GetHashCode(), queryExecuter, reusableQueryBuilder); return(CustomOverrides.TryAdd(cpa.Key, cpa)); }