< Summary

Information
Class: Elsa.Common.Converters.BooleanConverter
Assembly: Elsa.Common
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/Converters/BooleanConverter.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 9
Coverable lines: 9
Total lines: 29
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 7
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Read(...)0%5670%
Write(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/Converters/BooleanConverter.cs

#LineLine coverage
 1using System.Text.Json;
 2using System.Text.Json.Serialization;
 3
 4namespace Elsa.Common.Converters;
 5
 6public class BooleanConverter : JsonConverter<bool>
 7{
 8    public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
 9    {
 010        switch (reader.TokenType)
 11        {
 12            case JsonTokenType.True:
 013                return true;
 14            case JsonTokenType.False:
 015                return false;
 16            case JsonTokenType.String:
 017                var value = reader.GetString();
 018                if (bool.TryParse(value, out var b))
 019                    return b;
 20                break;
 21        }
 022        throw new JsonException($"Cannot convert {reader.TokenType} to bool");
 23    }
 24
 25    public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options)
 26    {
 027        writer.WriteBooleanValue(value);
 028    }
 29}