Exemple #1
0
        public override int Visit(IfNode obj)
        {
            bool b = _engine.EvalToBool(_engine.Eval(obj.Expr));

            if (b)
            {
                if (obj.TrueNode != null)
                {
                    return(obj.TrueNode.Accept(this));
                }
                else
                {
                    return(0);
                }
            }
            else
            {
                if (obj.FalseNode != null)
                {
                    return(obj.FalseNode.Accept(this));
                }
                else
                {
                    return(0);
                }
            }
        }
        protected override void DoCheck(IValidateResult result, object instance, object propertyValue)
        {
            //Extend:use cache to improve performance.
            ExpressionLanguageEngineConfig cfg    = new ExpressionLanguageEngineConfig(EvalExceptionHandlingPolicy.IgnorePolicy);
            ExpressionLanguageEngine       engine = ExpressionLanguageEngine.CreateEngine(cfg);

            engine.Assign(INSTANCE, instance);
            engine.Assign(VALUE, propertyValue);
            object b = engine.Eval(_expr);

            if (!engine.EvalToBool(b))
            {
                string msg = string.Format(MSG, _pInfo.Name, instance.GetType().Name, propertyValue, _expr);
                this.LogValidateResult(result, msg);
            }
        }