开发者

How to exit a method in the OnEntry method of a PostSharp aspect based on condition

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?**
            }
        }
    }

Any help much appreciated.


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;
            } 
        } 
    } 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜