Skip to content

Commit 17242fa

Browse files
committed
feat: add GetJson<T> to MsSqlDataReader for direct JSON deserialization
1 parent e06a8f8 commit 17242fa

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
<Authors>vkuttyp</Authors>
88
<PackageLicenseExpression>MIT</PackageLicenseExpression>
99
<RepositoryUrl>https://github.com/vkuttyp/CosmoSQLClient-Dotnet</RepositoryUrl>
10-
<Version>1.9.43</Version>
10+
<Version>1.9.44</Version>
1111
</PropertyGroup>
1212
</Project>

NuGetScratch/lock/24aa6aa4a9b0696c9c98a2adbec424b7e254ac59

Whitespace-only changes.

src/CosmoSQLClient.MsSql/MsSqlDataReader.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Text.Json;
12
using System.Collections;
23
using System.Data;
34
using System.Data.Common;
@@ -167,6 +168,16 @@ public override int GetValues(object[] values)
167168
public override Guid GetGuid(int ordinal) => Get(ordinal).AsGuid() ?? throw Null(ordinal);
168169
public override DateTime GetDateTime(int ordinal) => Get(ordinal).AsDate() ?? throw Null(ordinal);
169170

171+
public T? GetJson<T>(int ordinal)
172+
{
173+
var v = Get(ordinal);
174+
if (v.IsNull) return default;
175+
var json = v.AsString();
176+
return string.IsNullOrWhiteSpace(json) ? default : JsonSerializer.Deserialize<T>(json);
177+
}
178+
179+
public T? GetJson<T>(string name) => GetJson<T>(GetOrdinal(name));
180+
170181
public override char GetChar(int ordinal)
171182
{
172183
var s = GetString(ordinal);

0 commit comments

Comments
 (0)