Yes, you can do the replacement. The structure of your current expression looks like this:
Expression.Lambda
Expression.Add
Expression.Parameter("a")
Expression.Constant(1)
the structure of the new expression will look like this:
Expression.Lambda
Expression.BlockExpression
Expression.Call
Expression.Constant("Inside the function!")
MedhodInfo(Debug.WriteLine)
Expression.Add
Expression.Parameter("a")
Expression.Constant(1)
You will need to provide MedhodInfo
for the Debug.WriteLine
to the Call
expression. The last expression in the block (i.e. a+1
) will be considered block's return expression.