/// <summary> /// Process the output from the call so far and optionally modify the output. /// </summary> /// <param name="input">The input.</param> /// <param name="methodReturn">The method return.</param> /// <param name="callData">The per-call data.</param> /// <returns>IMethodReturn.</returns> protected override IMethodReturn PostInvoke( IMethodInvocation input, IMethodReturn methodReturn, CallTraceData callData) { // async methods are always dumped in ContinueWith if (!callData.Trace || !LogWriter.IsLoggingEnabled() || methodReturn.IsAsyncCall()) { return(methodReturn); } callData.ReturnValue = methodReturn.ReturnValue; callData.OutputValues = methodReturn.Outputs; callData.Exception = methodReturn.Exception; // if necessary wait for the async LogBeforeCall to finish if (callData.LogBeforeCall != null && !input.IsAsyncCall()) { callData.LogBeforeCall.GetAwaiter().GetResult(); } LogPostInvoke(input, callData).GetAwaiter().GetResult(); return(methodReturn); }
/// <summary> /// Creates and caches a new, closed/invokable continue-with method out of ContinueWith<T> for each method called on the target. /// </summary> /// <param name="input">The input.</param> /// <returns>MethodInfo.</returns> MethodInfo GetContinueWith( IMethodInvocation input) { if (input == null) { throw new ArgumentNullException(nameof(input)); } if (!input.IsAsyncCall()) { return(null); } var returnType = ((MethodInfo)input.MethodBase).ReturnType; var handlerTypeReturnType = new HandlerTypeReturnType(GetType(), returnType); MethodInfo continueWith; // if we have it cached already - return it using (SyncMethodToContinueWith.ReaderLock()) if (HandlerTypeReturnTypeToContinueWith.TryGetValue(handlerTypeReturnType, out continueWith)) { return(continueWith); } // get the continueWith MethodInfo MethodInfo genericContinueWith; using (SyncHandlerToGenericContinueWith.ReaderLock()) genericContinueWith = HandlerToGenericContinueWith[GetType()]; // if it is not overridden, it will be null! continueWith = genericContinueWith?.MakeGenericMethod(returnType); using (SyncMethodToContinueWith.WriterLock()) return(HandlerTypeReturnTypeToContinueWith[handlerTypeReturnType] = continueWith); }