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

loresoft / FluentCommand / 29258656563

13 Jul 2026 02:36PM UTC coverage: 65.856% (+0.2%) from 65.698%
29258656563

push

github

pwelter34
Add JsonElement converter support

1872 of 3634 branches covered (51.51%)

Branch coverage included in aggregate %.

17 of 28 new or added lines in 3 files covered. (60.71%)

14 existing lines in 2 files now uncovered.

5741 of 7926 relevant lines covered (72.43%)

298.72 hits per line

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

48.65
/src/FluentCommand/Handlers/JsonElementHandler.cs
1
using System.Data;
2
using System.Text.Json;
3

4
namespace FluentCommand.Handlers;
5

6
public class JsonElementHandler : IDataParameterHandler, IDataFieldConverter<JsonElement>
7
{
8
    /// <inheritdoc />
9
    public Type ValueType { get; } = typeof(JsonElement);
10

11
    /// <inheritdoc />
12
    public JsonElement ReadValue(IDataRecord dataRecord, int fieldIndex)
13
    {
14
        var value = dataRecord.GetValue(fieldIndex);
3✔
15

16
        return value switch
3!
17
        {
3✔
NEW
18
            JsonElement jsonElement => jsonElement,
×
19
            string stringValue => Parse(stringValue),
1✔
20
            _ => default
2✔
21
        };
3✔
22
    }
23

24
    /// <inheritdoc />
25
    public object? ReadValue(IDbDataParameter parameter)
26
    {
NEW
27
        return parameter.Value switch
×
NEW
28
        {
×
NEW
29
            JsonElement jsonElement => jsonElement,
×
NEW
30
            string stringValue => Parse(stringValue),
×
NEW
31
            _ => default
×
NEW
32
        };
×
33
    }
34

35
    /// <inheritdoc />
36
    public void SetValue(IDbDataParameter parameter, object? value)
37
    {
38
        parameter.DbType = DbType.String;
1✔
39
        parameter.Value = value switch
1!
40
        {
1✔
41
            JsonElement jsonElement => jsonElement.GetRawText(),
1✔
NEW
42
            null => DBNull.Value,
×
NEW
43
            _ => value.ToString()
×
44
        };
1✔
45
    }
1✔
46

47
    private static JsonElement Parse(string jsonString)
48
    {
49
        try
50
        {
51
#if NET10_0_OR_GREATER
52
            return JsonElement.Parse(jsonString);
1✔
53
#else
54
            using var document = JsonDocument.Parse(jsonString);
55
            return document.RootElement.Clone();
56
#endif
57
        }
NEW
58
        catch (JsonException)
×
59
        {
NEW
60
            return default;
×
61
        }
62
    }
1✔
63
}
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