public void Intercept(IInvocation invocation) { MethodInfo methodInfo = invocation.MethodInvocationTarget; if (methodInfo == null) { methodInfo = invocation.Method; } List<MethodBoundaryAttribute> attributes = GetAttributes(methodInfo); if (attributes.Count == 0) { invocation.Proceed(); } else { MethodExecutionArgs args = new MethodExecutionArgs( invocation.InvocationTarget, invocation.Method, invocation.Arguments); InvokeEntry(attributes, args); try { if (args.FlowBehavior == FlowBehavior.Return) invocation.ReturnValue = args.ReturnValue; else invocation.Proceed(); args.ReturnValue = invocation.ReturnValue; InvokeSuccess(attributes, args); } catch (System.Exception err) { args.Exception = err; InvokeException(attributes, args); if (args.FlowBehavior == FlowBehavior.Return) { invocation.ReturnValue = args.ReturnValue; return; } if (args.FlowBehavior != FlowBehavior.Continue) throw err; } finally { InvokeExit(attributes, args); } } }
public virtual void OnEntry(MethodExecutionArgs args) { }
public virtual void OnSuccess(MethodExecutionArgs args) { }
public virtual void OnExit(MethodExecutionArgs args) { }
public virtual void OnException(MethodExecutionArgs args) { }
private void InvokeEntry(List<MethodBoundaryAttribute> attributes, MethodExecutionArgs args) { foreach (MethodBoundaryAttribute attr in attributes) { attr.OnEntry(args); } }