private static Expression ApplyInterceptorsToCollection(Expression source, Type elementType, InterceptorContainer interceptorContainer) { interceptorContainer.ForEach(source, (src, predicate) => { var filterResult = Expression.Call( ExpressionHelperMethods.EnumerableWhereGeneric.MakeGenericMethod(elementType), src, predicate); source = filterResult; }); return(source); }
private static Expression ApplyInterceptorsToProperty(Expression source, Type elementType, InterceptorContainer interceptorContainer) { //return source; interceptorContainer.ForEach(source, (src, predicate) => { //var m = source as MemberExpression; //var p = m.Member as PropertyInfo; ////var newExp = PredicateRewriter.RewriteLambda(predicate, src.ToString()); //var methodCall = predicate.Body as MethodCallExpression; //var n = predicate.Substitute(, source); //var x = Expression.Lambda(predicate.Body, new[] { Expression.Parameter(m.Expression.Type) }.ToList()); var rewrittenExpression = new ParameterReplacerVisitor(predicate.Parameters[0].Name, src).Visit(predicate.Body); var filterResult = Expression.Condition( test: rewrittenExpression, ifTrue: src, ifFalse: Expression.Constant(elementType.GetDefault(), elementType), type: elementType); source = filterResult; }); return(source); }