public static IExpressionNode CreateNode(ExpressionTypes type)
        {
            IExpressionNode node = null;

            switch (type)
            {
                case ExpressionTypes.BlockExpression:
                    node = new PExpression();
                    break;
                case ExpressionTypes.StatementExpression:
                    node = new StatementExpressionNode();
                    break;
                case ExpressionTypes.UnaryExpression:
                    break;
                case ExpressionTypes.BinaryExpression:
                    node = new BinaryExpressionNode();
                    break;
                case ExpressionTypes.TernaryExpression:
                    break;
                case ExpressionTypes.IdentifierExpression:
                    break;
                case ExpressionTypes.ValueExpression:
                    node = new ValueExpressionNode();
                    break;
            }

            return node;
        }
Exemplo n.º 2
0
        IExpressionNode CreateNode(INode node)
        {
            IExpressionNode expressionNode = null;

            if (node is ExpressionStatement)
            {
                var statementNode = (ExpressionStatement)node;
                expressionNode = new StatementExpressionNode
                {
                    Expression = CreateNode(statementNode.Expression)
                };
            }
            else if (node is BinaryOperatorExpression)
            {
                var binaryNode = ((BinaryOperatorExpression)node);
                expressionNode = new BinaryExpressionNode
                {
                    Operator = (BinaryExpressionNode.Operators)binaryNode.Op,
                    Left = CreateNode(binaryNode.Left),
                    Right = CreateNode(binaryNode.Right),
                };
            }
            else if (node is PrimitiveExpression)
            {
                var primitiveNode = (PrimitiveExpression)node;
                var valueType = primitiveNode.Value == null ? typeof(object) : primitiveNode.Value.GetType();
                var value = (IValueNode)Activator.CreateInstance(typeof(ValueNode<>).MakeGenericType(valueType), primitiveNode.Value);
                expressionNode = new ValueExpressionNode
                {
                    Value = value,
                };
            }

            return expressionNode;
        }
Exemplo n.º 3
0
        public static IExpressionNode CreateNode(ExpressionTypes type)
        {
            IExpressionNode node = null;

            switch (type)
            {
            case ExpressionTypes.BlockExpression:
                node = new PExpression();
                break;

            case ExpressionTypes.StatementExpression:
                node = new StatementExpressionNode();
                break;

            case ExpressionTypes.UnaryExpression:
                break;

            case ExpressionTypes.BinaryExpression:
                node = new BinaryExpressionNode();
                break;

            case ExpressionTypes.TernaryExpression:
                break;

            case ExpressionTypes.IdentifierExpression:
                break;

            case ExpressionTypes.ValueExpression:
                node = new ValueExpressionNode();
                break;
            }

            return(node);
        }