< Summary - erichiller/mkmrk.Channels coverage

Information
Class: mkmrk.Channels.ThrowHelper
Assembly: mkmrk.Channels
File(s): /home/runner/work/mkmrk.Channels/mkmrk.Channels/src/mkmrk.Channels/ThrowHelper.cs
Tag: 161_8859726157
Line coverage
0%
Covered lines: 0
Uncovered lines: 4
Coverable lines: 4
Total lines: 57
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Metrics

File(s)

/home/runner/work/mkmrk.Channels/mkmrk.Channels/src/mkmrk.Channels/ThrowHelper.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Diagnostics;
 4using System.Diagnostics.CodeAnalysis;
 5
 6namespace mkmrk.Channels;
 7
 8/// <summary>
 9/// Utility class for throwing exceptions in an efficient way.
 10/// <para />
 11/// While there are <a href="https://stackoverflow.com/questions/1980044/when-should-i-use-a-throwhelper-method-instead-
 12/// the consensus amongst .NET runtime developers is that it is the correct way to go.
 13/// The runtime docs say <a href="https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/S
 14/// <i>It is very important we do this for generic classes because we can easily generate the same code multiple times f
 15/// <br/>
 16/// To facilitate use in methods or locations that must return a value, use one of the Generic helper methods, eg <c>pub
 17/// See <a href="https://learn.microsoft.com/en-us/dotnet/communitytoolkit/diagnostics/throwhelper#:~:text=within%20expr
 18///
 19/// <para/>There is one large downside, <b>the stack trace will start at the ThrowHelper method, not the method that cal
 20/// <para />
 21/// For background see:
 22///         <list type="bullet">
 23///     <item>
 24///         <description>https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Thr
 25///     </item>
 26///     <item>
 27///         <description>https://learn.microsoft.com/en-us/dotnet/communitytoolkit/diagnostics/throwhelper</description>
 28///     </item>
 29///     <item>
 30///         <description>https://dunnhq.com/posts/2022/throw-helper/</description>
 31///     </item>
 32/// </list>
 33/// </summary>
 34[ StackTraceHidden ]
 35internal static class ThrowHelper {
 36    /// <inheritdoc cref="ObjectDisposedException" />
 37    [ DoesNotReturn ]
 38    internal static TReturn ThrowObjectDisposedException<TReturn>( string typeNameDisposed ) =>
 039        throw new ObjectDisposedException( typeNameDisposed );
 40
 41    /// <inheritdoc cref="ObjectDisposedException" />
 42    [ DoesNotReturn ]
 43    internal static bool ThrowObjectDisposedException<TOut>( string typeNameDisposed, out TOut data ) =>
 044        throw new ObjectDisposedException( typeNameDisposed );
 45
 46    /// <inheritdoc cref="KeyNotFoundException" />
 47    [ DoesNotReturn ]
 48    internal static void ThrowKeyNotFoundException( string message ) =>
 049        throw new System.Collections.Generic.KeyNotFoundException( message );
 50
 51    /// <summary>
 52    /// Throw <see cref="InvalidCastException"/>, supplying the destination type for the message
 53    /// </summary>
 54    [ DoesNotReturn ]
 55    internal static TCast ThrowInvalidCastException<TInput, TCast>( TInput? variable )
 056        => throw new InvalidCastException( $"Unable to cast type {typeof(TInput).Name} with value {variable} to type {ty
 57}