如何根据条件退出 PostSharp 方面的 OnEntry 方法中的方法 [英] How to exit a method in the OnEntry method of a PostSharp aspect based on condition
本文介绍了如何根据条件退出 PostSharp 方面的 OnEntry 方法中的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望方面根据如下条件退出方法调用:
I'd like the aspect to exit a method invocation based on a condition like the following:
[AttributeUsage(AttributeTargets.Method)]
public class IgnoreIfInactiveAttribute : OnMethodBoundaryAspect
{
public override void OnEntry(MethodExecutionEventArgs eventArgs)
{
if (condition)
{
**// How can I make the method return here?**
}
}
}
非常感谢任何帮助.
推荐答案
好的,我自己想出来了.这里是造福大家的解决方案:
Ok I figured it out myself. Here the solution for the benefit of everyone:
[AttributeUsage(AttributeTargets.Method)]
public class IgnoreIfInactiveAttribute : OnMethodBoundaryAspect
{
public override void OnEntry(MethodExecutionEventArgs eventArgs)
{
if (condition)
{
eventArgs.FlowBehavior = FlowBehavior.Return;
}
}
}
这篇关于如何根据条件退出 PostSharp 方面的 OnEntry 方法中的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文