2010-03-13 55 views
5

一個PostSharp方面的OnEntry方法退出的方法,我想縱橫退出基於類似以下的條件的方法調用:如何根據病情

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

任何幫助非常讚賞。

回答

9

好吧我自己想清楚了。這裏爲大家帶來的利益解決方案:

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

沒錯。你也可以設置返回值(eventArgs.ReturnValue)。 – 2010-03-13 09:19:42

+0

嗨蓋爾, 這是否意味着被調用的方法隱式立即返回,如果我設置返回值屬性? – 2010-03-13 09:56:56