Given an PostSharp OnMethodBoundaryAspect of the following set-up, how do I get typeof(T1)
during OnEntry
or OnExit
:
Bonus Points for no reflection used.
Aspect:
public class MyOnMethodBoundaryAspect : OnMethodBoundaryAspect
{
public override void OnEntry(MethodExecutionArgs args)
{
//args.??? -- How to get typeof(T1)
}
}
Method:
[MyOnMethodBoundaryAspect]
public void Foo<T1>()
{
}
I haven't used PostSharp for ages, but it looks like you just need to use the Method
property:
If the executed method is generic or if its declaring type is generic, the current property contains the generic instance being executed.
So you should be able to use MethodBase.GetGenericArguments
to get at the type arguments.