If I want to replace this anonymous method:
Func<int, int> f = delegate(int i)
{
return i + 1;
};
with an expression tree, it would like this:
ParameterExpression i = Expression.Parameter(typeof(int), "i");
Expression one = Expression.Constant(1, typeof(int));
Expression body = Expression.Add(i, one);
Func<int, int> f = Expression.Lambda<Func<int, int>>(body, i).Compile();
(I know: an expression tree will secretly dynamically create another anymous method, but that is not the point).
Now I want to replace the following method with an expression tree:
Func<int, int> f = delegate(int i)
{
Debug.WriteLine("Inside the function!");
return i + 1;
};
Is there a way and how do I do this?