Как выйти из метода в методе OnEntry аспекта PostSharp в зависимости от условия - PullRequest
5 голосов
/ 13 марта 2010

Я бы хотел, чтобы аспект вышел из вызова метода на основе условия, подобного следующему:

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

Любая помощь высоко ценится.

1 Ответ

10 голосов
/ 13 марта 2010

Хорошо, я понял это сам. Вот решение на благо каждого:

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