开发者

What is the best way to log a .NET Func<>

开发者 https://www.devze.com 2023-02-10 05:00 出处:网络
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 hel开发者_如何学Cp me und

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 hel开发者_如何学Cp me understand what it is doing?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消