public void Intercept(IInvocation invocation) { if (ProfilerInterceptor.ReentrancyCounter > 0) { CallOriginal(invocation, false); return; } bool callOriginal = false; ProfilerInterceptor.GuardInternal(() => { var mockInvocation = new Invocation { Args = invocation.Arguments, Method = invocation.GetConcreteMethod(), Instance = invocation.Proxy, }; DebugView.TraceEvent(IndentLevel.Dispatch, () => String.Format("Intercepted DP call: {0}", mockInvocation.InputToString())); DebugView.PrintStackTrace(); var mock = MocksRepository.GetMockMixin(invocation.Proxy, invocation.Method.DeclaringType); var repo = mock != null ? mock.Repository : this.constructionRepo; lock (repo) { repo.DispatchInvocation(mockInvocation); } invocation.ReturnValue = mockInvocation.ReturnValue; callOriginal = mockInvocation.CallOriginal; if (callOriginal) { DebugView.TraceEvent(IndentLevel.DispatchResult, () => "Calling original implementation"); } else if (mockInvocation.IsReturnValueSet) { DebugView.TraceEvent(IndentLevel.DispatchResult, () => String.Format("Returning value '{0}'", invocation.ReturnValue)); } }); if (callOriginal) CallOriginal(invocation, true); }