< Summary

Information
Class: Elsa.Extensions.JsonElementExtensions
Assembly: Elsa.Expressions
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Expressions/Extensions/JsonElementExtensions.cs
Line coverage
58%
Covered lines: 7
Uncovered lines: 5
Coverable lines: 12
Total lines: 31
Line coverage: 58.3%
Branch coverage
44%
Covered branches: 4
Total branches: 9
Branch coverage: 44.4%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetValue(...)44.44%15958.33%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Expressions/Extensions/JsonElementExtensions.cs

#LineLine coverage
 1using System.Text.Json;
 2
 3// ReSharper disable once CheckNamespace
 4namespace Elsa.Extensions;
 5
 6/// <summary>
 7/// Parses a <see cref="JsonElement"/> into a .NET object.
 8/// </summary>
 9public static class JsonElementExtensions
 10{
 11    /// <summary>
 12    /// Parses a <see cref="JsonElement"/> into a .NET object.
 13    /// </summary>
 14    /// <param name="jsonElement">The JSON element to parse.</param>
 15    /// <returns>The parsed object.</returns>
 16    public static object? GetValue(this JsonElement jsonElement)
 17    {
 696318        return jsonElement.ValueKind switch
 696319        {
 142720            JsonValueKind.String => jsonElement.GetString(),
 021            JsonValueKind.Number => jsonElement.GetDecimal(),
 28222            JsonValueKind.True => true,
 497223            JsonValueKind.False => false,
 28224            JsonValueKind.Undefined => null,
 025            JsonValueKind.Null => null,
 026            JsonValueKind.Object => jsonElement.GetRawText(),
 027            JsonValueKind.Array => jsonElement.GetRawText(),
 028            _ => jsonElement.GetRawText()
 696329        };
 30    }
 31}