• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

f2calv / CasCap.Common / 13300409113

13 Feb 2025 04:26AM UTC coverage: 0.334% (-0.03%) from 0.362%
13300409113

push

github

web-flow
F2calv/2025 02 updates (#215)

* logging

* tidy

* consolidate and rework IPAFValue and related objects + midpoint calc

* lots more tidynig

* fixed one more PAF test with Array2DConverter

* nuget

* big IGI tidy-up, still loads more to do

* PostAsync to HttpMessageRequest/Response

* nuget updates

* tidy SendAsync and fix tests

* nuget updates

* lint fixes

* tidy

0 of 336 branches covered (0.0%)

Branch coverage included in aggregate %.

0 of 79 new or added lines in 5 files covered. (0.0%)

4 existing lines in 3 files now uncovered.

3 of 561 relevant lines covered (0.53%)

0.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/CasCap.Common.Serialization.Json/Extensions/JsonSerializationHelpers.cs
1
namespace CasCap.Common.Extensions;
2

3
public static class JsonSerializationHelpers
4
{
5
    private static readonly ILogger _logger = ApplicationLogging.CreateLogger(nameof(JsonSerializationHelpers));
×
6

7
    public static string ToJson(this object obj) => obj.ToJson(options: null);
×
8

9
    public static string ToJson(this object obj, JsonSerializerOptions? options)
10
    {
11
        obj = obj ?? throw new ArgumentNullException(paramName: nameof(obj));
×
12
        try
13
        {
14
            return JsonSerializer.Serialize(obj, options);
×
15
        }
16
        catch (Exception ex)
×
17
        {
18
            _logger.LogError(ex, "{className} {methodName} failed", nameof(JsonSerializationHelpers), nameof(JsonSerializer.Serialize));
×
19
            throw;
×
20
        }
21
    }
×
22

23
    public static T? FromJson<T>(this string json) => json.FromJson<T>(options: null);
×
24

25
    public static T? FromJson<T>(this string json, JsonSerializerOptions? options)
26
    {
27
        json = json ?? throw new ArgumentNullException(paramName: nameof(json));
×
28
        try
29
        {
30
            return JsonSerializer.Deserialize<T>(json, options);
×
31
        }
32
        catch (Exception ex)
×
33
        {
NEW
34
            _logger.LogError(ex, "{className} {methodName} failed to deserialize {objectType}",
×
NEW
35
                nameof(JsonSerializationHelpers), nameof(JsonSerializer.Deserialize), typeof(T));
×
UNCOV
36
            throw;
×
37
        }
38
    }
×
39

40
    public static bool TryFromJson<T>(this string json, out T? output, JsonSerializerOptions? options = null)
41
    {
NEW
42
        json = json ?? throw new ArgumentNullException(paramName: nameof(json));
×
NEW
43
        output = default;
×
44
        try
45
        {
NEW
46
            output = JsonSerializer.Deserialize<T>(json, options);
×
NEW
47
            return true;
×
48
        }
NEW
49
        catch (Exception ex)
×
50
        {
NEW
51
            _logger.LogWarning(ex, "{className} {methodName} failed to deserialize {objectType}",
×
NEW
52
                nameof(JsonSerializationHelpers), nameof(JsonSerializer.Deserialize), typeof(T));
×
NEW
53
        }
×
NEW
54
        return false;
×
NEW
55
    }
×
56

57
    public static T[,] To2D<T>(this List<List<T>> source)
58
    {
59
        // Adapted from this answer https://stackoverflow.com/a/26291720/3744182
60
        // By https://stackoverflow.com/users/3909293/diligent-key-presser
61
        // To https://stackoverflow.com/questions/26291609/converting-jagged-array-to-2d-array-c-sharp
NEW
62
        var firstDim = source.Count;
×
NEW
63
        var secondDim = source.Select(row => row.Count).FirstOrDefault();
×
NEW
64
        if (!source.All(row => row.Count == secondDim))
×
NEW
65
            throw new InvalidOperationException();
×
NEW
66
        var result = new T[firstDim, secondDim];
×
NEW
67
        for (var i = 0; i < firstDim; i++)
×
NEW
68
            for (int j = 0, count = source[i].Count; j < count; j++)
×
NEW
69
                result[i, j] = source[i][j];
×
NEW
70
        return result;
×
71
    }
72

73
    public static void WriteOrSerialize<T>(this JsonConverter<T> converter, Utf8JsonWriter writer, T value, JsonSerializerOptions options)
74
    {
NEW
75
        if (converter != null)
×
NEW
76
            converter.Write(writer, value, options);
×
77
        else
NEW
78
            JsonSerializer.Serialize(writer, value, typeof(T), options);
×
NEW
79
    }
×
80
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc