protected override ExpressionBody Transform(Ast.LambdaExpression lmx)
        {
            var parameters    = lmx.Parameters.Select(px => Tuple.Create(px, LX.Parameter(typeof(LogEventPropertyValue), px.ParameterName))).ToList();
            var paramSwitcher = new ExpressionConstantMapper(parameters.ToDictionary(px => (object)px.Item1, px => (System.Linq.Expressions.Expression)px.Item2));
            var rewritten     = paramSwitcher.Visit(Transform(lmx.Body));

            Type delegateType;

            if (lmx.Parameters.Length == 1)
            {
                delegateType = typeof(Func <LogEventPropertyValue, LogEventPropertyValue>);
            }
            else if (lmx.Parameters.Length == 2)
            {
                delegateType = typeof(Func <LogEventPropertyValue, LogEventPropertyValue, LogEventPropertyValue>);
            }
            else
            {
                throw new NotSupportedException("Unsupported lambda signature.");
            }

            var lambda = LX.Lambda(delegateType, rewritten !, parameters.Select(px => px.Item2).ToArray());

            // Unfortunately, right now, functions need to be threaded through in constant scalar values :-D
            return(LX.New(typeof(ScalarValue).GetConstructor(new[] { typeof(object) }) !,
                          LX.Convert(lambda, typeof(object))));
        }
Ejemplo n.º 2
0
 public virtual Ast.Expression VisitLambdaExpression(Ast.LambdaExpression expression)
 {
     if (expression.Body != null)
     {
         return(this.Visit(expression.Body));
     }
     return(expression);
 }
Ejemplo n.º 3
0
        public override Ast.Expression VisitLambdaExpression(Ast.LambdaExpression expression)
        {
            WriteNewLine();
            writer.Write("where");
            WriteNewLine();

            this.Visit(expression.Body);

            return(expression);
        }