public void ExecutesDelegatePerformance() { Hashtable vars = new Hashtable(5); WaitCallback noop = delegate (object arg) { // noop }; vars["noop"] = noop; FunctionNode fn = new FunctionNode(); fn.Text = "noop"; StringLiteralNode str = new StringLiteralNode(); str.Text = "theArg"; fn.addChild(str); int ITERATIONS = 10000000; StopWatch watch = new StopWatch(); using (watch.Start("Duration Direct: {0}")) { for (int i = 0; i < ITERATIONS; i++) { ((WaitCallback)vars["noop"])(str.getText()); } } using (watch.Start("Duration SpEL: {0}")) { for (int i = 0; i < ITERATIONS; i++) { fn.GetValue(null, vars); } } }
public void CanCreatePublicInstance() { ConstructorNode ctorNode = new ConstructorNode(typeof(PublicTestClass)); StringLiteralNode sNode = new StringLiteralNode("theValue"); ctorNode.AddArgument(sNode); PublicTestClass instance = (PublicTestClass) ((IExpression)ctorNode).GetValue(); Assert.AreEqual( sNode.Text, instance._s ); Assert.AreEqual( -1, instance._i ); }
public void CanCreatePublicInstance() { ConstructorNode ctorNode = new ConstructorNode(typeof(PublicTestClass)); StringLiteralNode sNode = new StringLiteralNode("theValue"); ctorNode.AddArgument(sNode); PublicTestClass instance = (PublicTestClass)((IExpression)ctorNode).GetValue(); Assert.AreEqual(sNode.Text, instance._s); Assert.AreEqual(-1, instance._i); }
public void ExecutesLambdaFunction() { Hashtable vars = new Hashtable(); Expression.RegisterFunction("ident", "{|n| $n}", vars); FunctionNode fn = new FunctionNode(); fn.Text = "ident"; StringLiteralNode str = new StringLiteralNode(); str.Text = "theValue"; fn.addChild(str); IExpression exp = fn; Assert.AreEqual(str.Text, exp.GetValue(null, vars)); }
public void CanCreatePublicInstanceWithNonPublicConstructor() { ConstructorNode ctorNode = new ConstructorNode(); ctorNode.Text=typeof(PublicTestClass).FullName; StringLiteralNode sNode = new StringLiteralNode(); sNode.Text = "theValue2"; ctorNode.addChild(sNode); IntLiteralNode iNode = new IntLiteralNode(); iNode.Text="2"; ctorNode.addChild(iNode); PublicTestClass instance = (PublicTestClass) ((IExpression)ctorNode).GetValue(); Assert.AreEqual( sNode.Text, instance._s ); Assert.AreEqual( 2, instance._i ); }
public void ExecutesDelegate() { Hashtable vars = new Hashtable(); vars["concat"] = new TestCallback(Concat); FunctionNode fn = new FunctionNode(); fn.Text = "concat"; StringLiteralNode str = new StringLiteralNode(); str.Text = "theValue"; fn.addChild(str); StringLiteralNode str2 = new StringLiteralNode(); str2.Text = "theValue"; fn.addChild(str2); IExpression exp = fn; Assert.AreEqual(string.Format("{0},{1},{2}", this.GetHashCode(), str.Text, str2.Text), exp.GetValue(null, vars)); }
public void PerformanceOfMethodEvaluationOnDifferentContextTypes() { MethodNode mn = new MethodNode(); mn.Text = "ToString"; TypeNode nln = new TypeNode(); nln.Text = "System.Globalization.CultureInfo"; PropertyOrFieldNode pn = new PropertyOrFieldNode(); pn.Text = "InvariantCulture"; Expression exp = new Expression(); exp.addChild(nln); exp.addChild(pn); StringLiteralNode sln = new StringLiteralNode(); sln.Text = "dummy"; mn.addChild(sln); mn.addChild(exp); IExpression mnExp = mn; Assert.AreEqual("dummy", mnExp.GetValue(0m, null)); int runs = 10000000; StopWatch watch = new StopWatch(); using (watch.Start("Duration: {0}")) { for (int i = 0; i < runs; i++) { mnExp.GetValue(0m, null); } } }
public void CanCreateNonPublicInstanceWithNonPublicConstructor() { ConstructorNode ctorNode = new ConstructorNode(); ctorNode.Text = typeof(PrivateTestClass).FullName; StringLiteralNode sNode = new StringLiteralNode(); sNode.Text = "theValue3"; ctorNode.addChild(sNode); IntLiteralNode iNode = new IntLiteralNode(); iNode.Text = "3"; ctorNode.addChild(iNode); PublicTestClass instance = (PublicTestClass)((IExpression)ctorNode).GetValue(); Assert.AreEqual(sNode.Text, instance._s); Assert.AreEqual(3, instance._i); }