示例#1
0
        public void TestValidate()
        {
            // test success
            orNode.AddChildNode(new SupportExprNode(typeof(bool?)));
            orNode.AddChildNode(new SupportExprNode(typeof(bool?)));
            orNode.Validate(SupportExprValidationContextFactory.MakeEmpty(container));

            // test failure, type mismatch
            orNode.AddChildNode(new SupportExprNode(typeof(string)));
            try
            {
                orNode.Validate(SupportExprValidationContextFactory.MakeEmpty(container));
                Assert.Fail();
            }
            catch (ExprValidationException)
            {
                // Expected
            }

            // test failed - with just one child
            orNode = new ExprOrNode();
            orNode.AddChildNode(new SupportExprNode(typeof(bool?)));
            try
            {
                orNode.Validate(SupportExprValidationContextFactory.MakeEmpty(container));
                Assert.Fail();
            }
            catch (ExprValidationException)
            {
                // Expected
            }
        }
示例#2
0
 public ExprOrNodeEval(
     ExprOrNode parent,
     ExprEvaluator[] evaluators)
 {
     this._parent = parent;
     this._evaluators = evaluators;
 }
示例#3
0
        public void TestEvaluate()
        {
            orNode.AddChildNode(new SupportBoolExprNode(true));
            orNode.AddChildNode(new SupportBoolExprNode(false));
            SupportExprNodeUtil.Validate(container, orNode);
            Assert.IsTrue((bool)orNode.Forge.ExprEvaluator.Evaluate(null, false, null));

            orNode = new ExprOrNode();
            orNode.AddChildNode(new SupportBoolExprNode(false));
            orNode.AddChildNode(new SupportBoolExprNode(false));
            SupportExprNodeUtil.Validate(container, orNode);
            Assert.IsFalse((bool)orNode.Forge.ExprEvaluator.Evaluate(null, false, null));

            orNode = new ExprOrNode();
            orNode.AddChildNode(new SupportExprNode(null, typeof(bool?)));
            orNode.AddChildNode(new SupportExprNode(false));
            SupportExprNodeUtil.Validate(container, orNode);
            Assert.IsNull(orNode.Forge.ExprEvaluator.Evaluate(null, false, null));
        }
示例#4
0
        public static CodegenExpression Codegen(
            ExprOrNode parent,
            CodegenMethodScope codegenMethodScope,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            var methodNode = codegenMethodScope.MakeChild(typeof(bool?), typeof(ExprOrNodeEval), codegenClassScope);

            var block = methodNode.Block
                .DeclareVar<bool?>("result", ConstantFalse());

            var count = -1;
            foreach (var child in parent.ChildNodes) {
                count++;
                var childType = child.Forge.EvaluationType;
                if (childType.CanNotBeNull()) {
                    block.IfCondition(
                            child.Forge.EvaluateCodegen(typeof(bool?), methodNode, exprSymbol, codegenClassScope))
                        .BlockReturn(ConstantTrue());
                }
                else {
                    var refname = "r" + count;
                    block.DeclareVar<bool?>(
                            refname,
                            child.Forge.EvaluateCodegen(typeof(bool?), methodNode, exprSymbol, codegenClassScope))
                        .IfCondition(EqualsNull(Ref(refname)))
                        .AssignRef("result", ConstantNull())
                        .IfElse()
                        .IfCondition(ExprDotName(Ref(refname), "Value"))
                        .BlockReturn(ConstantTrue());
                }
            }

            block.MethodReturn(Ref("result"));
            return LocalMethod(methodNode);
        }
示例#5
0
 public void SetUp()
 {
     orNode = new ExprOrNode();
 }