< Summary

Information
Class: Chronicler.Diagnostics.DiagnosticMessageHandler<T>
Assembly: Chronicler.Diagnostics
File(s): /home/runner/work/Chronicler/Chronicler/src/Chronicler.Diagnostics/DiagnosticMessageHandler.cs
Line coverage
100%
Covered lines: 17
Uncovered lines: 0
Coverable lines: 17
Total lines: 93
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
.ctor(...)100%11100%
.ctor(...)100%11100%
get_IsEnabled()100%11100%
get_Message()100%11100%
AppendLiteral(...)100%11100%
AppendFormatted(...)100%11100%
AppendFormatted(...)100%11100%
AppendFormatted(...)100%11100%
AppendFormatted(...)100%11100%

File(s)

/home/runner/work/Chronicler/Chronicler/src/Chronicler.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 Chronicler.Diagnostics;
 9
 10using System.Runtime.CompilerServices;
 11
 12/// <summary>Builds a diagnostic message using an enablement decision captured at construction.</summary>
 13/// <typeparam name="TLevel">The default provider for fixed-level calls. The dynamic constructor takes a level explicitl
 14/// <remarks>The compiler uses the constructor's gate to skip interpolation expressions when disabled. Append calls on a
 15[InterpolatedStringHandler]
 16public ref struct DiagnosticMessageHandler<TLevel>
 17    where TLevel : struct, IDiagnosticLevelProvider
 18{
 19    private DiagnosticInterpolatedStringHandler _message;
 20
 21    /// <summary>
 22    /// Initializes a new handler for a fixed-level diagnostic message.
 23    /// </summary>
 24    /// <param name="literalLength">The compiler-supplied count of literal UTF-16 code units.</param>
 25    /// <param name="formattedCount">The compiler-supplied number of interpolation holes.</param>
 26    /// <param name="channel">The diagnostic channel that receives the message.</param>
 27    /// <param name="isEnabled">Set to true to evaluate interpolation expressions, or false to skip them.</param>
 28    /// <exception cref="System.ArgumentNullException">The channel is null.</exception>
 29    public DiagnosticMessageHandler(
 30        int literalLength,
 31        int formattedCount,
 32        DiagnosticChannel channel,
 33        out bool isEnabled)
 21234        : this(literalLength, formattedCount, channel, default(TLevel).Level, out isEnabled)
 35    {
 21136    }
 37
 38    /// <summary>
 39    /// Initializes a new handler for a dynamic-level diagnostic message.
 40    /// </summary>
 41    /// <param name="literalLength">The compiler-supplied count of literal UTF-16 code units.</param>
 42    /// <param name="formattedCount">The compiler-supplied number of interpolation holes.</param>
 43    /// <param name="channel">The diagnostic channel that receives the message.</param>
 44    /// <param name="level">The diagnostic level being evaluated.</param>
 45    /// <param name="isEnabled">Set to true to evaluate interpolation expressions, or false to skip them.</param>
 46    /// <exception cref="System.ArgumentNullException">The channel is null.</exception>
 47    public DiagnosticMessageHandler(
 48        int literalLength,
 49        int formattedCount,
 50        DiagnosticChannel channel,
 51        DiagnosticLevel level,
 52        out bool isEnabled)
 53    {
 21754        ChronicleGuard.ThrowIfNull(channel, nameof(channel));
 21555        _message = new DiagnosticInterpolatedStringHandler(literalLength, formattedCount, channel, level, out isEnabled)
 21556    }
 57
 58    /// <summary>Gets the captured formatting gate.</summary>
 59    /// <value>True when the handler was constructed to build a message.</value>
 21460    public bool IsEnabled => _message.IsEnabled;
 61
 862    internal DiagnosticInterpolatedStringHandler Message => _message;
 63
 64    /// <inheritdoc cref="DiagnosticInterpolatedStringHandler.AppendLiteral(string)"/>
 65    public void AppendLiteral(string value)
 66    {
 1167        _message.AppendLiteral(value);
 1168    }
 69
 70    /// <inheritdoc cref="DiagnosticInterpolatedStringHandler.AppendFormatted{T}(T)"/>
 71    public void AppendFormatted<T>(T value)
 72    {
 773        _message.AppendFormatted(value);
 774    }
 75
 76    /// <inheritdoc cref="DiagnosticInterpolatedStringHandler.AppendFormatted{T}(T, string)"/>
 77    public void AppendFormatted<T>(T value, string format)
 78    {
 179        _message.AppendFormatted(value, format);
 180    }
 81
 82    /// <inheritdoc cref="DiagnosticInterpolatedStringHandler.AppendFormatted{T}(T, int)"/>
 83    public void AppendFormatted<T>(T value, int alignment)
 84    {
 185        _message.AppendFormatted(value, alignment);
 186    }
 87
 88    /// <inheritdoc cref="DiagnosticInterpolatedStringHandler.AppendFormatted{T}(T, int, string)"/>
 89    public void AppendFormatted<T>(T value, int alignment, string format)
 90    {
 191        _message.AppendFormatted(value, alignment, format);
 192    }
 93}