< Summary

Information
Class: Elsa.Api.Client.Extensions.JsonElementExtensions
Assembly: Elsa.Api.Client
File(s): /home/runner/work/elsa-core/elsa-core/src/clients/Elsa.Api.Client/Extensions/JsonElementExtensions.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 7
Coverable lines: 7
Total lines: 26
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
TryGetPropertySafe(...)0%2040%

File(s)

/home/runner/work/elsa-core/elsa-core/src/clients/Elsa.Api.Client/Extensions/JsonElementExtensions.cs

#LineLine coverage
 1using System.Text.Json;
 2
 3namespace Elsa.Api.Client.Extensions;
 4
 5/// <summary>
 6/// Provides extension methods for <see cref="JsonElement"/>.
 7/// </summary>
 8public static class JsonElementExtensions
 9{
 10    /// <summary>
 11    /// Returns the value of the specified property if it exists, otherwise the default value.
 12    /// </summary>
 13    public static bool TryGetPropertySafe(this JsonElement element, string propertyName, out JsonElement value)
 14    {
 015        value = default;
 16
 017        if(element.ValueKind != JsonValueKind.Object)
 018            return false;
 19
 020        if (!element.TryGetProperty(propertyName, out var property))
 021            return false;
 22
 023        value = property;
 024        return true;
 25    }
 26}