< Summary - SonghayCore

Information
Class: Songhay.Extensions.Utf8JsonWriterExtensions
Assembly: SonghayCore
File(s): /home/rasx/sourceRoot/SonghayCore/SonghayCore/Extensions/Utf8JsonWriterExtensions.cs
Line coverage
100%
Covered lines: 16
Uncovered lines: 0
Coverable lines: 16
Total lines: 53
Line coverage: 100%
Branch coverage
75%
Covered branches: 6
Total branches: 8
Branch coverage: 75%
Method coverage

Method coverage is only available for sponsors.

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
WriteObject(...)75%4100%
WriteObject(...)75%4100%

File(s)

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

#LineLine coverage
 1namespace Songhay.Extensions;
 2
 3/// <summary>
 4/// Extensions of <see cref="Utf8JsonWriter"/>
 5/// </summary>
 6public static class Utf8JsonWriterExtensions
 7{
 8    /// <summary>
 9    /// Wrap <see cref="Utf8JsonWriter"/> statements
 10    /// inside <see cref="Utf8JsonWriter.WriteStartObject()"/>
 11    /// and <see cref="Utf8JsonWriter.WriteEndObject"/>.
 12    /// </summary>
 13    /// <param name="writer">the <see cref="Utf8JsonWriter"/></param>
 14    /// <param name="writerAction"></param>
 15    /// <remarks>
 16    /// This method is for building a JSON object.
 17    /// </remarks>
 18    public static Utf8JsonWriter? WriteObject(this Utf8JsonWriter? writer, Action? writerAction)
 219    {
 220        if (writer == null) return writer;
 21
 222        writer.WriteStartObject();
 223        writerAction?.Invoke();
 224        writer.WriteEndObject();
 25
 226        return writer;
 227    }
 28
 29    /// <summary>
 30    /// Wrap <see cref="Utf8JsonWriter"/> statements
 31    /// inside <see cref="Utf8JsonWriter.WritePropertyName(string)"/>
 32    /// <see cref="Utf8JsonWriter.WriteStartObject()"/>
 33    /// and <see cref="Utf8JsonWriter.WriteEndObject"/>.
 34    /// </summary>
 35    /// <param name="writer">the <see cref="Utf8JsonWriter"/></param>
 36    /// <param name="propertyName"></param>
 37    /// <param name="writerAction"></param>
 38    /// <remarks>
 39    /// This method is for building a JSON object for a JSON property.
 40    /// </remarks>
 41    public static Utf8JsonWriter? WriteObject(this Utf8JsonWriter? writer, string propertyName, Action? writerAction)
 442    {
 443        if (writer == null) return writer;
 444        propertyName.ThrowWhenNullOrWhiteSpace();
 45
 446        writer.WritePropertyName(propertyName);
 447        writer.WriteStartObject();
 448        writerAction?.Invoke();
 449        writer.WriteEndObject();
 50
 451        return writer;
 452    }
 53}