< Summary

Information
Class: Elsa.Common.Converters.BigIntegerJsonConverter
Assembly: Elsa.Common
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/Converters/BigIntegerJsonConverter.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 8
Coverable lines: 8
Total lines: 33
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
Read(...)0%2040%
Write(...)100%210%

File(s)

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

#LineLine coverage
 1using System.Numerics;
 2using System.Text.Json;
 3using System.Text.Json.Serialization;
 4
 5namespace Elsa.Common.Converters;
 6
 7/// <summary>
 8/// Converts big integers to and from JSON strings.
 9/// </summary>
 10public class BigIntegerJsonConverter : JsonConverter<BigInteger>
 11{
 12    /// <inheritdoc />
 13    public override BigInteger Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
 14    {
 015        if (reader.TokenType == JsonTokenType.Number)
 016            return reader.GetInt64();
 17
 018        if (reader.TokenType == JsonTokenType.String)
 19        {
 020            var value = reader.GetString()!;
 021            return long.Parse(value);
 22        }
 23
 024        throw new JsonException("Expected number or string.");
 25    }
 26
 27    /// <inheritdoc />
 28    public override void Write(Utf8JsonWriter writer, BigInteger value, JsonSerializerOptions options)
 29    {
 30        // Write the Big Integer as a JSON number.
 031        writer.WriteNumberValue((long)value);
 032    }
 33}