Skip to content

Commit 4125c10

Browse files
[8.19] Add 3 case JSON union type matching method (#8821) (#8822)
Co-authored-by: Florian Bernd <git@flobernd.de>
1 parent 44dc5a5 commit 4125c10

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/Elastic.Clients.Elasticsearch/_Shared/Next/JsonUnionSelector.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public static UnionTag T2(ref Utf8JsonReader reader, JsonSerializerOptions optio
7777
}
7878

7979
// We avoid using a `params` array for performance reasons. Create `Match()` overloads with additional parameters as needed.
80+
8081
public static UnionTag Match(ref Utf8JsonReader reader, JsonSerializerOptions options, JsonUnionSelectorFunc case1, JsonUnionSelectorFunc case2)
8182
{
8283
if (case1(ref reader, options) is var tag1 and not UnionTag.None)
@@ -92,6 +93,27 @@ public static UnionTag Match(ref Utf8JsonReader reader, JsonSerializerOptions op
9293
return UnionTag.None;
9394
}
9495

96+
public static UnionTag Match(ref Utf8JsonReader reader, JsonSerializerOptions options, JsonUnionSelectorFunc case1, JsonUnionSelectorFunc case2,
97+
JsonUnionSelectorFunc case3)
98+
{
99+
if (case1(ref reader, options) is var tag1 and not UnionTag.None)
100+
{
101+
return tag1;
102+
}
103+
104+
if (case2(ref reader, options) is var tag2 and not UnionTag.None)
105+
{
106+
return tag2;
107+
}
108+
109+
if (case3(ref reader, options) is var tag3 and not UnionTag.None)
110+
{
111+
return tag3;
112+
}
113+
114+
return UnionTag.None;
115+
}
116+
95117
public static UnionTag MatchTokenTypes(ref Utf8JsonReader reader, JsonSerializerOptions options, JsonTokenTypes types, JsonUnionSelectorFunc next)
96118
{
97119
if (((int)types & (1 << (int)reader.TokenType)) is not 0)

0 commit comments

Comments
 (0)