public void InvokeExpressionTest5() { Expression <Func <int, int> > rootExpression = x => ClassForTest.GetLength(x.ToString()); var subExpression = ((MethodCallExpression)rootExpression.Body).Arguments[0]; // just the `x.ToString()` part Assert.AreEqual("123", InvokeSubExpression <string>(rootExpression, subExpression, 123)); // we pass root parameter but evaluate the sub-expression only }
public void InvokeExpressionTest4() { Expression <Func <int, int> > rootExpression = x => Math.Abs(x) + ClassForTest.GetLength(x.ToString()); var subExpression = ((BinaryExpression)rootExpression.Body).Right; Assert.AreEqual(3, InvokeSubExpression <int>(rootExpression, subExpression, 123)); // we pass root parameter but evaluate the sub-expression only }