I have following code:
public static void ProcessStep(Action action)
{
//do something here
if (Attribute.IsDefined(action.Method, typeof(LogAttribute)))
{
//do something here [1]
}
action();
//do something here
}
For easy use I have some similar methods using method above. For example:
public static void ProcessStep(Action<bool> action)
{
ProcessStep(() => action(true)); //this is only example, don't bother about hardcoded true
}
But when I use the second method (the one above), even if original action had attribute, code [1] will not be executed.
How can I find if method is only wrapper and underlying method contains attribute and how to access this attribute?
While I’m sure you could use expression trees, the easiest solution would be to just create an overload that takes an additional parameter of type MethodInfo and use it like this: