// Method call with ref argument public void MethodCallWithRefArgument() { Expression <Func <ActivityContext, int> > expression = (env) => DummyHelper.MethodCallWithRefArgument(ref DummyHelper.StaticIntField); string methodName = "MethodCallWithRefArgument"; TestExpression expr = new TestExpression() { ResultType = typeof(int), ExpectedNode = new InvokeMethod <int>() { MethodName = methodName, TargetType = typeof(DummyHelper), Parameters = { new InOutArgument <int>() { Expression = new FieldReference <DummyHelper, int> { FieldName = "StaticIntField" }, EvaluationOrder = 1 } } }, ExpressionTree = expression }; ExpressionTestRuntime.ValidateExpressionXaml <int>(expr); ExpressionTestRuntime.ValidateExecutionResult(expr, null); }
// Comments copied from ExpressionServices.cs: // This is to handle the leaf nodes as a variable // // Linq actually generate a temp class wrapping all the local variables. // // The real expression object look like // new TempClass() { A = a }.A.Get(env) // // A is a field // // This is why the logic of the code below follows. // This is pretty dependent on Linq implementation. // The test is to simulate the scenario by creating the Linq expression as: // (env) => TempClass().A.Get(env) public static Expression GetMemberAccessVariableExpression <T>() { MethodInfo getMethodInfo = typeof(Variable <T>).GetMethod("Get", new Type[] { typeof(ActivityContext) }); DummyHelper dummy = new DummyHelper(); // DummyHelper.<T>Var = LeafHelper.GetVariable<T>(); FieldInfo fieldInfo; fieldInfo = typeof(DummyHelper).GetField(typeof(T).Name + "Var"); fieldInfo.SetValue(dummy, LeafHelper.GetVariable <T>()); return(Expression.Call( Expression.Field(Expression.Constant(dummy), typeof(DummyHelper).GetField(typeof(T).Name + "Var")), getMethodInfo, TestExpression.EnvParameter)); }
// Method call with different expressions as argument public void MethodCallWithVariousParameters() { Activity <int> expectedActivity = new InvokeMethod <int>() { MethodName = "MethodCallWithVariousArgs", TargetType = typeof(DummyHelper), Parameters = { new InArgument <int>(-1) { EvaluationOrder = 1 }, new InArgument <string>("hello") { EvaluationOrder = 2, }, new InOutArgument <int>() { EvaluationOrder = 3, Expression = new FieldReference <DummyHelper, int>() { FieldName = "StaticIntField" }, }, new InArgument <Variable <int?> >() { EvaluationOrder = 4, Expression = new FieldValue <DummyHelper, Variable <int?> >() { FieldName = "StaticNullableIntVar" } }, new InArgument <Func <int, int> >() { EvaluationOrder = 5, Expression = new FieldValue <DummyHelper, Func <int, int> >() { FieldName = "StaticDelegate" } }, new InArgument <DummyHelper>() { EvaluationOrder = 6, Expression = new New <DummyHelper>() } }, }; Expression <Func <ActivityContext, int> > expectedExpression = (env) => DummyHelper.MethodCallWithVariousArgs(-1, "hello", ref DummyHelper.StaticIntField, DummyHelper.StaticNullableIntVar, DummyHelper.StaticDelegate, new DummyHelper()); TestExpression expr = new TestExpression() { ResultType = typeof(int), ExpectedNode = expectedActivity, ExpressionTree = expectedExpression }; ExpressionTestRuntime.ValidateExpressionXaml <int>(expr); ExpressionTestRuntime.ValidateExecutionResult(expr, null); }
// Method call with VarArg public void TryMethodCallWithVarArg() { ExpressionTestRuntime.TryConvert((env) => DummyHelper.MethodCallWithVarArg(1, 2, 3), false); }
// Method call with VarArg public void MethodCallWithVarArg() { TargetInvocationException expectedException = new TargetInvocationException(null); ExpressionTestRuntime.Convert((env) => DummyHelper.MethodCallWithVarArg(1, 2, 3), expectedException); }
// TryConvert method call with ref argument public void TryConvertMethodCallWithRefArgument() { int i = 100; ExpressionTestRuntime.TryConvert((env) => DummyHelper.MethodCallWithRefArgument(ref i), true); }
public static int MethodCallWithVariousArgs(int intArg, string stringArg, ref int refArg, Variable <int?> genericArg, Func <int, int> delegateArg, DummyHelper instanceArg) { return(0); }