public object InvokeOriginalFunction(CancellationToken cancellationToken) { // This method fixes up the arguments before the invocation so that // CancellationToken is set to the correct one and CallOptions are reset. // In addition, it processes CallOptions.Capture, though note that // it's also processed in InterceptedFunction.TryGetExisting. var method = Method; var arguments = Arguments; var ctIndex = method.CancellationTokenArgumentIndex; Invocation.SetCurrentInterceptorIndex(NextInterceptorIndex); if (ctIndex >= 0) { var currentCancellationToken = (CancellationToken)arguments[ctIndex]; // Comparison w/ the existing one to avoid boxing when possible if (currentCancellationToken != cancellationToken) { // ReSharper disable once HeapView.BoxingAllocation arguments[ctIndex] = cancellationToken; Invocation.Proceed(); arguments[ctIndex] = BoxedDefaultCancellationToken; } else { Invocation.Proceed(); } } else { Invocation.Proceed(); } return(Invocation.ReturnValue); }