Is it possible to use reflection in CompileTimeInitialize
in PostSharp 3.1?
Following code worked in 3.0:
public class TestClass
{
public string TestField;
[TestAspect]
public void TestMethod() { }
}
public class TestAspect : OnMethodBoundaryAspect
{
private LocationInfo locationInfo;
public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo)
{
this.locationInfo = new LocationInfo(method.ReflectedType.GetField("TestField"));
}
public override void OnSuccess(MethodExecutionArgs args)
{
Console.WriteLine(this.locationInfo);
}
}
With the 3.1 upgrade, this.locationInfo
becomes Missing Property
and accessing any of its properties cause NullReferenceException
.
Was I doing this a wrong way or has this been changed in 3.1 upgrade? If so, can you suggest me the right way to approach this?
PS: If I set this.locationInfo
in RuntimeInitialize
things work properly.