私は次のコードを持っています:
public static void ProcessStep(Action action)
{
//do something here
if (Attribute.IsDefined(action.Method, typeof(LogAttribute)))
{
//do something here [1]
}
action();
//do something here
}
簡単に使用するために、上記の方法を使用していくつかの同様の方法があります。例えば:
public static void ProcessStep(Action<bool> action)
{
ProcessStep(() => action(true)); //this is only example, don't bother about hardcoded true
}
しかし、2番目の方法(上記)を使用すると、元のアクションに属性があったとしても、コード[1]は実行されません。
メソッドがラッパーのみで、基になるメソッドに属性が含まれているかどうか、およびこの属性にアクセスする方法を見つけるにはどうすればよいですか?