Пример #1
0
        public static ExecutionNode Compile(Expression expression, ConstantExpression[] constExpressions, ParameterExpression[] parameterExpressions)
        {
            if (expression == null)
            {
                return(NullNode.Instance);
            }

            if (constExpressions == null)
            {
                throw new ArgumentNullException("constExpressions");
            }
            if (parameterExpressions == null)
            {
                throw new ArgumentNullException("parameterExpressions");
            }

            switch (expression.NodeType)
            {
            case ExpressionType.ArrayIndex:
                return(new ArrayIndexNode(expression, constExpressions, parameterExpressions));

            case ExpressionType.Coalesce:
                return(new CoalesceNode((BinaryExpression)expression, constExpressions, parameterExpressions));

            case ExpressionType.Add:
            case ExpressionType.AddChecked:
            case ExpressionType.And:
            case ExpressionType.AndAlso:
            case ExpressionType.Divide:
            case ExpressionType.Equal:
            case ExpressionType.ExclusiveOr:
            case ExpressionType.GreaterThan:
            case ExpressionType.GreaterThanOrEqual:
            case ExpressionType.LeftShift:
            case ExpressionType.LessThan:
            case ExpressionType.LessThanOrEqual:
            case ExpressionType.Modulo:
            case ExpressionType.Multiply:
            case ExpressionType.MultiplyChecked:
            case ExpressionType.NotEqual:
            case ExpressionType.Or:
            case ExpressionType.OrElse:
            case ExpressionType.Power:
            case ExpressionType.RightShift:
            case ExpressionType.Subtract:
            case ExpressionType.SubtractChecked:
                return(BinaryNode.Create((BinaryExpression)expression, constExpressions, parameterExpressions));

            case ExpressionType.ArrayLength:
                return(new ArrayLengthNode((UnaryExpression)expression, constExpressions, parameterExpressions));

            case ExpressionType.Negate:
            case ExpressionType.UnaryPlus:
            case ExpressionType.NegateChecked:
            case ExpressionType.Not:
                return(UnaryNode.Create((UnaryExpression)expression, constExpressions, parameterExpressions));

            case ExpressionType.Quote:
                return(new QuoteNode((UnaryExpression)expression));

            case ExpressionType.Call:
                return(new CallNode((MethodCallExpression)expression, constExpressions, parameterExpressions));

            case ExpressionType.Conditional:
                return(new ConditionalNode((ConditionalExpression)expression, constExpressions, parameterExpressions));

            case ExpressionType.Constant:
                return(new ConstantNode((ConstantExpression)expression, constExpressions));

            case ExpressionType.Invoke:
                return(new InvocationNode((InvocationExpression)expression, constExpressions, parameterExpressions));

            case ExpressionType.Lambda:
                return(new LambdaNode((LambdaExpression)expression, parameterExpressions));

            case ExpressionType.ListInit:
                return(new ListInitNode((ListInitExpression)expression, constExpressions, parameterExpressions));

            case ExpressionType.MemberAccess:
                return(new MemberAccessNode((MemberExpression)expression, constExpressions, parameterExpressions));

            case ExpressionType.MemberInit:
                return(new MemberInitNode((MemberInitExpression)expression, constExpressions, parameterExpressions));

            case ExpressionType.New:
                return(new NewNode((NewExpression)expression, constExpressions, parameterExpressions));

            case ExpressionType.NewArrayInit:
                return(new NewArrayInitNode((NewArrayExpression)expression, constExpressions, parameterExpressions));

            case ExpressionType.NewArrayBounds:
                return(new NewArrayBoundsNode((NewArrayExpression)expression, constExpressions, parameterExpressions));

            case ExpressionType.Parameter:
                return(new ParameterNode((ParameterExpression)expression, parameterExpressions));

            case ExpressionType.Convert:
            case ExpressionType.ConvertChecked:
                return(new ConvertNode((UnaryExpression)expression, constExpressions, parameterExpressions));

            case ExpressionType.TypeAs:
                return(new TypeAsNode((UnaryExpression)expression, constExpressions, parameterExpressions));

            case ExpressionType.TypeIs:
                return(new TypeIsNode((TypeBinaryExpression)expression, constExpressions, parameterExpressions));

            default:
                throw new InvalidOperationException(string.Format(Properties.Resources.EXCEPTION_COMPIL_UNKNOWNEXPRTYPE, expression.Type));
            }
        }