< Summary - SonghayCore

Information
Class: Songhay.Extensions.StringBuilderExtensions
Assembly: SonghayCore
File(s): /home/rasx/sourceRoot/SonghayCore/SonghayCore/Extensions/StringBuilderExtensions.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 16
Coverable lines: 16
Total lines: 58
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 12
Branch coverage: 0%
Method coverage

Method coverage is only available for sponsors.

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
AppendLabelWithValue(...)100%10%
AppendLabelWithValue(...)100%10%
AppendLabelWithValue(...)0%120%

File(s)

/home/rasx/sourceRoot/SonghayCore/SonghayCore/Extensions/StringBuilderExtensions.cs

#LineLine coverage
 1namespace Songhay.Extensions;
 2
 3/// <summary>
 4/// Extensions of <see cref="StringBuilder"/>
 5/// </summary>
 6public static class StringBuilderExtensions
 7{
 8    /// <summary>
 9    /// Appends the label with value.
 10    /// </summary>
 11    /// <param name="builder">The builder.</param>
 12    /// <param name="name">The name.</param>
 13    /// <param name="value">The value.</param>
 14    public static void AppendLabelWithValue(this StringBuilder? builder, string name, object? value) =>
 015        builder.AppendLabelWithValue(name, value, defaultValue: null, hasLineBreak: false);
 16
 17    /// <summary>
 18    /// Appends the label with value.
 19    /// </summary>
 20    /// <param name="builder">The builder.</param>
 21    /// <param name="name">The name.</param>
 22    /// <param name="value">The value.</param>
 23    /// <param name="defaultValue">The default value.</param>
 24    public static void AppendLabelWithValue(this StringBuilder? builder, string name, object? value,
 025        string? defaultValue) => builder.AppendLabelWithValue(name, value, defaultValue, hasLineBreak: false);
 26
 27    /// <summary>
 28    /// Appends the label with value.
 29    /// </summary>
 30    /// <param name="builder">The builder.</param>
 31    /// <param name="name">The name.</param>
 32    /// <param name="value">The value.</param>
 33    /// <param name="defaultValue">The default value.</param>
 34    /// <param name="hasLineBreak">When <c>true</c> add <see cref="Environment.NewLine" /> between label and value.</par
 35    /// <remarks>
 36    /// This method will append <c>name: value</c> to the appending <see cref="StringBuilder"/>.
 37    /// This is useful when overriding <see cref="object.ToString"/>.
 38    /// </remarks>
 39    public static void AppendLabelWithValue(this StringBuilder? builder, string name, object? value,
 40        string? defaultValue, bool hasLineBreak)
 041    {
 042        if (builder == null) return;
 043        if (value == null && string.IsNullOrWhiteSpace(defaultValue)) return;
 44
 045        if (hasLineBreak)
 046        {
 047            builder.Append($"{name}:");
 048            builder.AppendLine();
 049            builder.Append($"{value ?? defaultValue}");
 050        }
 51        else
 052        {
 053            builder.Append($"{name}: {value ?? defaultValue}");
 054        }
 55
 056        builder.AppendLine();
 057    }
 58}