如何基于条件退出PostSharp方面的OnEntry方法中的方法

Mic*_*ann 5 c# aop postsharp

我希望方面基于如下条件退出方法调用:

    [AttributeUsage(AttributeTargets.Method)]
    public class IgnoreIfInactiveAttribute : OnMethodBoundaryAspect
    {
        public override void OnEntry(MethodExecutionEventArgs eventArgs)
        {
             if (condition)
            {
                **// How can I make the method return here?**
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

任何帮助非常感谢.

Mic*_*ann 10

好的,我自己想通了.这里的解决方案为每个人的利益:

    [AttributeUsage(AttributeTargets.Method)] 
    public class IgnoreIfInactiveAttribute : OnMethodBoundaryAspect 
    { 
        public override void OnEntry(MethodExecutionEventArgs eventArgs) 
        { 
             if (condition) 
            { 
                eventArgs.FlowBehavior = FlowBehavior.Return;
            } 
        } 
    } 
Run Code Online (Sandbox Code Playgroud)