public void Test() { ExpressionLanguageEngine engine = ExpressionLanguageEngine.CreateEngine(); engine.Assign("m", 10); engine.Assign("v", 5); float E = engine.Eval <float>("m*v*v/2"); Assert.AreEqual(125, E); }
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); } }
public void Test1() { string expr = "(a>b)?a:b"; object res = engine.Eval(expr); Assert.AreEqual(10, res); }
public override int Visit(LetNode obj) { _ctx.Assign(obj.VarName, _engine.Eval(obj.Expression)); return(0); }