創建一個簡單的類來測試PostSharp中的OnExceptionAspect。PostSharp OnExceptionAspect不按預期方式工作
[Serializable]
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
public class ExceptionSwallower : OnExceptionAspect
{
public override void OnException(MethodExecutionEventArgs eventArgs)
{
eventArgs.FlowBehavior = FlowBehavior.Return;
base.OnException(eventArgs);
}
}
添加的屬性的方法
[ExceptionSwallower]
public void SomeMethod()
{
throw new Exception();
}
和調用它。
然而,異常實際上並沒有吞噬,這似乎很奇怪。
我一直沒能找到任何類似的問題,所以我希望有我沒有得到正確的一些次要的事情。任何人?
Pfft ...來吧Gael,我們都知道PostSharp引用System.Magic。 – 2012-05-24 01:54:03