< Summary

Information
Class: SwiftCollections.Diagnostics.WarningDiagnosticLevel
Assembly: SwiftCollections
File(s): /home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Diagnostics/DiagnosticMessageHandler.cs
Line coverage
100%
Covered lines: 1
Uncovered lines: 0
Coverable lines: 1
Total lines: 163
Line coverage: 100%
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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Level()100%11100%

File(s)

/home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Diagnostics/DiagnosticMessageHandler.cs

#LineLine coverage
 1//=======================================================================
 2// DiagnosticMessageHandler.cs
 3//=======================================================================
 4// MIT License, Copyright (c) 2024–present David Oravsky (mrdav30)
 5// See LICENSE file in the project root for full license information.
 6//=======================================================================
 7
 8namespace SwiftCollections.Diagnostics;
 9
 10using System.Runtime.CompilerServices;
 11
 12/// <summary>
 13/// Describes a fixed diagnostic level for an interpolated diagnostic message handler.
 14/// </summary>
 15public interface IDiagnosticLevelProvider
 16{
 17    /// <summary>
 18    /// Gets the diagnostic level for this provider.
 19    /// </summary>
 20    DiagnosticLevel Level { get; }
 21}
 22
 23/// <summary>
 24/// Provides the info diagnostic level for fixed-level interpolated logging.
 25/// </summary>
 26public readonly struct InfoDiagnosticLevel : IDiagnosticLevelProvider
 27{
 28    /// <inheritdoc />
 29    public DiagnosticLevel Level => DiagnosticLevel.Info;
 30}
 31
 32/// <summary>
 33/// Provides the warning diagnostic level for fixed-level interpolated logging.
 34/// </summary>
 35public readonly struct WarningDiagnosticLevel : IDiagnosticLevelProvider
 36{
 37    /// <inheritdoc />
 338    public DiagnosticLevel Level => DiagnosticLevel.Warning;
 39}
 40
 41/// <summary>
 42/// Provides the error diagnostic level for fixed-level interpolated logging.
 43/// </summary>
 44public readonly struct ErrorDiagnosticLevel : IDiagnosticLevelProvider
 45{
 46    /// <inheritdoc />
 47    public DiagnosticLevel Level => DiagnosticLevel.Error;
 48}
 49
 50/// <summary>
 51/// Provides a placeholder level for dynamic-level interpolated logging.
 52/// </summary>
 53public readonly struct DynamicDiagnosticLevel : IDiagnosticLevelProvider
 54{
 55    /// <inheritdoc />
 56    public DiagnosticLevel Level => DiagnosticLevel.None;
 57}
 58
 59/// <summary>
 60/// Builds interpolated diagnostic messages only when the requested diagnostic level is enabled.
 61/// </summary>
 62/// <typeparam name="TLevel">The fixed diagnostic level provider used by fixed-level helpers.</typeparam>
 63[InterpolatedStringHandler]
 64public ref struct DiagnosticMessageHandler<TLevel>
 65    where TLevel : struct, IDiagnosticLevelProvider
 66{
 67    private DiagnosticInterpolatedStringHandler _message;
 68
 69    /// <summary>
 70    /// Initializes a new handler for a fixed-level diagnostic message.
 71    /// </summary>
 72    /// <param name="literalLength">The combined length of literal portions in the interpolated string.</param>
 73    /// <param name="formattedCount">The number of formatted expressions in the interpolated string.</param>
 74    /// <param name="channel">The diagnostic channel that receives the message.</param>
 75    /// <param name="isEnabled">Set to <see langword="true"/> when formatted expressions should be evaluated.</param>
 76    public DiagnosticMessageHandler(
 77        int literalLength,
 78        int formattedCount,
 79        DiagnosticChannel channel,
 80        out bool isEnabled)
 81        : this(literalLength, formattedCount, channel, default(TLevel).Level, out isEnabled)
 82    {
 83    }
 84
 85    /// <summary>
 86    /// Initializes a new handler for a dynamic-level diagnostic message.
 87    /// </summary>
 88    /// <param name="literalLength">The combined length of literal portions in the interpolated string.</param>
 89    /// <param name="formattedCount">The number of formatted expressions in the interpolated string.</param>
 90    /// <param name="channel">The diagnostic channel that receives the message.</param>
 91    /// <param name="level">The diagnostic level being evaluated.</param>
 92    /// <param name="isEnabled">Set to <see langword="true"/> when formatted expressions should be evaluated.</param>
 93    public DiagnosticMessageHandler(
 94        int literalLength,
 95        int formattedCount,
 96        DiagnosticChannel channel,
 97        DiagnosticLevel level,
 98        out bool isEnabled)
 99    {
 100        SwiftThrowHelper.ThrowIfNull(channel, nameof(channel));
 101        _message = new DiagnosticInterpolatedStringHandler(literalLength, formattedCount, channel, level, out isEnabled)
 102    }
 103
 104    /// <summary>
 105    /// Gets whether the handler is actively building a diagnostic message.
 106    /// </summary>
 107    public bool IsEnabled => _message.IsEnabled;
 108
 109    internal DiagnosticInterpolatedStringHandler Message => _message;
 110
 111    /// <summary>
 112    /// Appends a literal string segment.
 113    /// </summary>
 114    /// <param name="value">The literal string segment.</param>
 115    public void AppendLiteral(string value)
 116    {
 117        _message.AppendLiteral(value);
 118    }
 119
 120    /// <summary>
 121    /// Appends a formatted value.
 122    /// </summary>
 123    /// <typeparam name="T">The type of value to append.</typeparam>
 124    /// <param name="value">The value to append.</param>
 125    public void AppendFormatted<T>(T value)
 126    {
 127        _message.AppendFormatted(value);
 128    }
 129
 130    /// <summary>
 131    /// Appends a formatted value using the specified format string.
 132    /// </summary>
 133    /// <typeparam name="T">The type of value to append.</typeparam>
 134    /// <param name="value">The value to append.</param>
 135    /// <param name="format">The format string to apply.</param>
 136    public void AppendFormatted<T>(T value, string format)
 137    {
 138        _message.AppendFormatted(value, format);
 139    }
 140
 141    /// <summary>
 142    /// Appends a formatted value with the specified alignment.
 143    /// </summary>
 144    /// <typeparam name="T">The type of value to append.</typeparam>
 145    /// <param name="value">The value to append.</param>
 146    /// <param name="alignment">The minimum width for the formatted value.</param>
 147    public void AppendFormatted<T>(T value, int alignment)
 148    {
 149        _message.AppendFormatted(value, alignment);
 150    }
 151
 152    /// <summary>
 153    /// Appends a formatted value with the specified alignment and format string.
 154    /// </summary>
 155    /// <typeparam name="T">The type of value to append.</typeparam>
 156    /// <param name="value">The value to append.</param>
 157    /// <param name="alignment">The minimum width for the formatted value.</param>
 158    /// <param name="format">The format string to apply.</param>
 159    public void AppendFormatted<T>(T value, int alignment, string format)
 160    {
 161        _message.AppendFormatted(value, alignment, format);
 162    }
 163}

Methods/Properties

get_Level()