< Summary

Information
Class: System.Net.Http.CancellationHelper
Assembly: System.Net.Http
File(s): D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\CancellationHelper.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 13
Coverable lines: 13
Total lines: 53
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%110%
ShouldWrapInOperationCanceledException(...)0%220%
CreateOperationCanceledException(...)100%110%
ThrowOperationCanceledException(...)100%110%
ThrowIfCancellationRequested(...)100%110%
ThrowIfCancellationRequested(...)0%220%

File(s)

D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\CancellationHelper.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Threading;
 5using System.Threading.Tasks;
 6
 7namespace System.Net.Http
 8{
 9    /// <summary>Provides utilities related to cancellation.</summary>
 10    internal static class CancellationHelper
 11    {
 12        /// <summary>The default message used by <see cref="OperationCanceledException"/>.</summary>
 013        private static readonly string s_cancellationMessage = new OperationCanceledException().Message; // use same mes
 14
 15        /// <summary>Determines whether to wrap an <see cref="Exception"/> in a cancellation exception.</summary>
 16        /// <param name="exception">The exception.</param>
 17        /// <param name="cancellationToken">The <see cref="CancellationToken"/> that may have triggered the exception.</
 18        /// <returns>true if the exception should be wrapped; otherwise, false.</returns>
 19        internal static bool ShouldWrapInOperationCanceledException(Exception exception, CancellationToken cancellationT
 020            !(exception is OperationCanceledException) && cancellationToken.IsCancellationRequested;
 21
 22        /// <summary>Creates a cancellation exception.</summary>
 23        /// <param name="innerException">The inner exception to wrap. May be null.</param>
 24        /// <param name="cancellationToken">The <see cref="CancellationToken"/> that triggered the cancellation.</param>
 25        /// <returns>The cancellation exception.</returns>
 26        internal static Exception CreateOperationCanceledException(Exception? innerException, CancellationToken cancella
 027            new TaskCanceledException(s_cancellationMessage, innerException, cancellationToken); // TCE for compatibilit
 28
 29        /// <summary>Throws a cancellation exception.</summary>
 30        /// <param name="innerException">The inner exception to wrap. May be null.</param>
 31        /// <param name="cancellationToken">The <see cref="CancellationToken"/> that triggered the cancellation.</param>
 32        private static void ThrowOperationCanceledException(Exception? innerException, CancellationToken cancellationTok
 033            throw CreateOperationCanceledException(innerException, cancellationToken);
 34
 35        /// <summary>Throws a cancellation exception if cancellation has been requested via <paramref name="cancellation
 36        /// <param name="cancellationToken">The token to check for a cancellation request.</param>
 37        internal static void ThrowIfCancellationRequested(CancellationToken cancellationToken)
 038        {
 039            ThrowIfCancellationRequested(innerException: null, cancellationToken);
 040        }
 41
 42        /// <summary>Throws a cancellation exception if cancellation has been requested via <paramref name="cancellation
 43        /// <param name="innerException">The inner exception to wrap. May be null.</param>
 44        /// <param name="cancellationToken">The token to check for a cancellation request.</param>
 45        internal static void ThrowIfCancellationRequested(Exception? innerException, CancellationToken cancellationToken
 046        {
 047            if (cancellationToken.IsCancellationRequested)
 048            {
 049                ThrowOperationCanceledException(innerException, cancellationToken);
 050            }
 051        }
 52    }
 53}