Reputation: 3913
I have a generic method that accepts a Func<int>
and I would like to log the Func that is passed into the method. What properties are available on the passed in func to help me understand what it is doing?
Upvotes: 7
Views: 413
Reputation: 3913
As Jaroslav Jandek pointed out by using Expression<Func<T>>
I can get more information about the method being passed in. Specifically: I found that the body
property has the anonymous method signature as a string.
http://msdn.microsoft.com/en-us/library/system.linq.expressions.lambdaexpression.body.aspx
Upvotes: 3
Reputation: 37516
You can log the method name with func.Method.Name
, and there's some other useful properties in the MethodInfo
class. However, if the Func
is anonymous, then you will not get a very helpful name.
Upvotes: 5