コード例 #1
0
        private IEnumerable EnumerateTest <T>(int level, int maxLevel)
        {
            // for non-leaf node, it could be a binary expression or one of the pre-defined node
            if (level < maxLevel)
            {
                foreach (BinaryOperator op in _operators)
                {
                    TestBinaryExpression binaryExpression = new TestBinaryExpression();
                    binaryExpression.ResultType = typeof(T);
                    binaryExpression.Operator   = op;
                    foreach (TestExpression left in EnumerateTest <T>(level + 1, maxLevel))
                    {
                        left.ResultType       = typeof(T);
                        binaryExpression.Left = left;
                        foreach (TestExpression right in EnumerateTest <T>(level + 1, maxLevel))
                        {
                            right.ResultType       = typeof(T);
                            binaryExpression.Right = right;
                            yield return(binaryExpression);
                        }
                    }
                }
            }

            // leaf node return const node only
            if (level == maxLevel)
            {
                NodeExpressionPair leaf = LeafHelper.GetConstNode(typeof(T));
                yield return(new TestExpression()
                {
                    ExpectedNode = leaf.GetLeafNode(),
                    ExpressionTree = leaf.LeafExpression
                });
            }
            // root can't be leaf node
            else if (level != 0)
            {
                foreach (NodeExpressionPair leaf in _leafNode)
                {
                    Exception expectedException = null;
                    object    expectedNode      = null;
                    try
                    {
                        expectedNode = leaf.GetLeafNode();
                    }
                    catch (Exception ex)
                    {
                        expectedException = ex;
                    }

                    TestExpression te = new TestExpression()
                    {
                        ExpectedConversionException = expectedException,
                        ExpectedNode   = expectedNode,
                        ExpressionTree = leaf.LeafExpression
                    };
                    yield return(te);
                }
            }
        }
コード例 #2
0
        private IEnumerable EnumerateTest <T>(int level, int maxLevel)
        {
            // for non-leaf node, it could be a unary expression or one of the pre-defined node
            if (level < maxLevel)
            {
                foreach (UnaryOperator op in _operators)
                {
                    TestUnaryExpression expression = new TestUnaryExpression
                    {
                        ResultType = typeof(T)
                    };
                    expression.ResultType = typeof(T);
                    expression.Operator   = op;
                    foreach (TestExpression operand in EnumerateTest <T>(level + 1, maxLevel))
                    {
                        operand.ResultType = typeof(T);
                        expression.Operand = operand;
                        yield return(expression);
                    }
                }
            }

            // leaf node return const node only
            if (level == maxLevel)
            {
                NodeExpressionPair leaf = LeafHelper.GetConstNode(typeof(T));
                yield return(new TestExpression()
                {
                    ExpectedNode = leaf.GetLeafNode(),
                    ExpressionTree = leaf.LeafExpression
                });
            }
            // root can't be leaf node
            else if (level != 0)
            {
                foreach (NodeExpressionPair leaf in _leafNode)
                {
                    TestExpression te = new TestExpression()
                    {
                        ExpectedNode   = leaf.GetLeafNode(),
                        ExpressionTree = leaf.LeafExpression
                    };
                    yield return(te);
                }
            }
        }