Beispiel #1
0
            public Expression ConvertExp(LinqExp.Expression linqExpression)
            {
                if (linqExpression == null)
                {
                    return(null);
                }

                switch (linqExpression.NodeType)
                {
                case LinqExp.ExpressionType.Add:
                    return(Convert((LinqExp.BinaryExpression)linqExpression, Expression.Add));

                case LinqExp.ExpressionType.AddChecked:
                    return(Convert((LinqExp.BinaryExpression)linqExpression, Expression.AddChecked));

                case LinqExp.ExpressionType.And:
                    return(Convert((LinqExp.BinaryExpression)linqExpression, Expression.And));

                case LinqExp.ExpressionType.AndAlso:
                    return(Convert((LinqExp.BinaryExpression)linqExpression, Expression.AndAlso));

                case LinqExp.ExpressionType.ArrayLength:
                    return(Convert((LinqExp.UnaryExpression)linqExpression, Expression.ArrayLength));

                case LinqExp.ExpressionType.ArrayIndex:
                    return(ConvertImplicit((LinqExp.BinaryExpression)linqExpression, Expression.ArrayIndex));

                case LinqExp.ExpressionType.Call:
                    return(Convert((LinqExp.MethodCallExpression)linqExpression));

                case LinqExp.ExpressionType.Coalesce:
                    return(ConvertImplicit((LinqExp.BinaryExpression)linqExpression, Expression.Coalesce));

                case LinqExp.ExpressionType.Conditional:
                    return(Convert((LinqExp.ConditionalExpression)linqExpression));

                case LinqExp.ExpressionType.Constant:
                    return(Convert((LinqExp.ConstantExpression)linqExpression));

                case LinqExp.ExpressionType.Convert:
                    return(ConvertCast((LinqExp.UnaryExpression)linqExpression, Expression.Convert));

                case LinqExp.ExpressionType.ConvertChecked:
                    return(ConvertCast((LinqExp.UnaryExpression)linqExpression, Expression.ConvertChecked));

                case LinqExp.ExpressionType.Divide:
                    return(Convert((LinqExp.BinaryExpression)linqExpression, Expression.Divide));

                case LinqExp.ExpressionType.Equal:
                    return(ConvertImplicit((LinqExp.BinaryExpression)linqExpression, Expression.Equal));

                case LinqExp.ExpressionType.ExclusiveOr:
                    return(ConvertImplicit((LinqExp.BinaryExpression)linqExpression, Expression.ExclusiveOr));

                case LinqExp.ExpressionType.GreaterThan:
                    return(ConvertImplicit((LinqExp.BinaryExpression)linqExpression, Expression.GreaterThan));

                case LinqExp.ExpressionType.GreaterThanOrEqual:
                    return(ConvertImplicit((LinqExp.BinaryExpression)linqExpression, Expression.GreaterThanOrEqual));

                case LinqExp.ExpressionType.Invoke:
                    return(Convert((LinqExp.InvocationExpression)linqExpression));

                case LinqExp.ExpressionType.Lambda:
                    return(ConvertLambda((LinqExp.LambdaExpression)linqExpression));

                case LinqExp.ExpressionType.LeftShift:
                    return(Convert((LinqExp.BinaryExpression)linqExpression, Expression.LeftShift));

                case LinqExp.ExpressionType.LessThan:
                    return(ConvertImplicit((LinqExp.BinaryExpression)linqExpression, Expression.LessThan));

                case LinqExp.ExpressionType.LessThanOrEqual:
                    return(ConvertImplicit((LinqExp.BinaryExpression)linqExpression, Expression.LessThanOrEqual));

                case LinqExp.ExpressionType.ListInit:
                    return(Convert((LinqExp.ListInitExpression)linqExpression));

                case LinqExp.ExpressionType.MemberAccess:
                    return(Convert((LinqExp.MemberExpression)linqExpression));

                case LinqExp.ExpressionType.MemberInit:
                    return(Convert((LinqExp.MemberInitExpression)linqExpression));

                case LinqExp.ExpressionType.Modulo:
                    return(Convert((LinqExp.BinaryExpression)linqExpression, Expression.Modulo));

                case LinqExp.ExpressionType.Multiply:
                    return(Convert((LinqExp.BinaryExpression)linqExpression, Expression.Multiply));

                case LinqExp.ExpressionType.MultiplyChecked:
                    return(Convert((LinqExp.BinaryExpression)linqExpression, Expression.MultiplyChecked));

                case LinqExp.ExpressionType.Negate:
                    return(Convert((LinqExp.UnaryExpression)linqExpression, Expression.Negate));

                case LinqExp.ExpressionType.UnaryPlus:
                    return(Convert((LinqExp.UnaryExpression)linqExpression, Expression.NegateChecked));

                case LinqExp.ExpressionType.NegateChecked:
                    return(Convert((LinqExp.UnaryExpression)linqExpression, Expression.NegateChecked));

                case LinqExp.ExpressionType.New:
                    return(Convert((LinqExp.NewExpression)linqExpression));

                case LinqExp.ExpressionType.NewArrayBounds:
                    return(Convert((LinqExp.NewArrayExpression)linqExpression, Expression.NewArrayBounds));

                case LinqExp.ExpressionType.NewArrayInit:
                    return(Convert((LinqExp.NewArrayExpression)linqExpression, Expression.NewArrayInit));

                case LinqExp.ExpressionType.Not:
                    return(Convert((LinqExp.UnaryExpression)linqExpression, Expression.Not));

                case LinqExp.ExpressionType.NotEqual:
                    return(ConvertImplicit((LinqExp.BinaryExpression)linqExpression, Expression.NotEqual));

                case LinqExp.ExpressionType.Or:
                    return(Convert((LinqExp.BinaryExpression)linqExpression, Expression.Or));

                case LinqExp.ExpressionType.OrElse:
                    return(Convert((LinqExp.BinaryExpression)linqExpression, Expression.OrElse));

                case LinqExp.ExpressionType.Parameter:
                    return(Convert((LinqExp.ParameterExpression)linqExpression));

                case LinqExp.ExpressionType.Power:
                    return(Convert((LinqExp.BinaryExpression)linqExpression, Expression.Power));

                case LinqExp.ExpressionType.Quote:
                    return(Convert((LinqExp.UnaryExpression)linqExpression, Expression.Quote));

                case LinqExp.ExpressionType.RightShift:
                    return(Convert((LinqExp.BinaryExpression)linqExpression, Expression.RightShift));

                case LinqExp.ExpressionType.Subtract:
                    return(Convert((LinqExp.BinaryExpression)linqExpression, Expression.Subtract));

                case LinqExp.ExpressionType.SubtractChecked:
                    return(Convert((LinqExp.BinaryExpression)linqExpression, Expression.SubtractChecked));

                case LinqExp.ExpressionType.TypeAs:
                    return(Convert((LinqExp.UnaryExpression)linqExpression, Expression.TypeAs));

                case LinqExp.ExpressionType.TypeIs:
                    return(Convert((LinqExp.TypeBinaryExpression)linqExpression));
                }

                throw new NotSupportedException("Can't convert a " + linqExpression.NodeType);
            }
Beispiel #2
0
 /// <summary>
 /// Converts the given <paramref name="linqExpression"/> into a DynamicLanguageRuntime Expression.
 /// </summary>
 /// <param name="linqExpression">The Linq Expression to convert.</param>
 /// <returns>The given <paramref name="linqExpression"/> converted into a DynamicLanguageRuntime Expression.</returns>
 public static Expression Convert(LinqExp.Expression linqExpression)
 => new Converter().ConvertExp(linqExpression);