@@ -20,6 +20,16 @@ namespace Algolia.Search.Models.Recommend;
20
20
[ JsonConverter ( typeof ( HighlightResultJsonConverter ) ) ]
21
21
public partial class HighlightResult : AbstractSchema
22
22
{
23
+ /// <summary>
24
+ /// Initializes a new instance of the HighlightResult class
25
+ /// with a Dictionary{string, HighlightResult}
26
+ /// </summary>
27
+ /// <param name="actualInstance">An instance of Dictionary<string, HighlightResult>.</param>
28
+ public HighlightResult ( Dictionary < string , HighlightResult > actualInstance )
29
+ {
30
+ ActualInstance = actualInstance ?? throw new ArgumentException ( "Invalid instance found. Must not be null." ) ;
31
+ }
32
+
23
33
/// <summary>
24
34
/// Initializes a new instance of the HighlightResult class
25
35
/// with a HighlightResultOption
@@ -56,6 +66,16 @@ public HighlightResult(List<HighlightResultOption> actualInstance)
56
66
/// </summary>
57
67
public sealed override object ActualInstance { get ; set ; }
58
68
69
+ /// <summary>
70
+ /// Get the actual instance of `Dictionary{string, HighlightResult}`. If the actual instance is not `Dictionary{string, HighlightResult}`,
71
+ /// the InvalidClassException will be thrown
72
+ /// </summary>
73
+ /// <returns>An instance of Dictionary<string, HighlightResult></returns>
74
+ public Dictionary < string , HighlightResult > AsDictionaryHighlightResult ( )
75
+ {
76
+ return ( Dictionary < string , HighlightResult > ) ActualInstance ;
77
+ }
78
+
59
79
/// <summary>
60
80
/// Get the actual instance of `HighlightResultOption`. If the actual instance is not `HighlightResultOption`,
61
81
/// the InvalidClassException will be thrown
@@ -71,7 +91,7 @@ public HighlightResultOption AsHighlightResultOption()
71
91
/// the InvalidClassException will be thrown
72
92
/// </summary>
73
93
/// <returns>An instance of Dictionary<string, HighlightResultOption></returns>
74
- public Dictionary < string , HighlightResultOption > AsDictionary ( )
94
+ public Dictionary < string , HighlightResultOption > AsDictionaryHighlightResultOption ( )
75
95
{
76
96
return ( Dictionary < string , HighlightResultOption > ) ActualInstance ;
77
97
}
@@ -81,12 +101,21 @@ public Dictionary<string, HighlightResultOption> AsDictionary()
81
101
/// the InvalidClassException will be thrown
82
102
/// </summary>
83
103
/// <returns>An instance of List<HighlightResultOption></returns>
84
- public List < HighlightResultOption > AsList ( )
104
+ public List < HighlightResultOption > AsListHighlightResultOption ( )
85
105
{
86
106
return ( List < HighlightResultOption > ) ActualInstance ;
87
107
}
88
108
89
109
110
+ /// <summary>
111
+ /// Check if the actual instance is of `Dictionary{string, HighlightResult}` type.
112
+ /// </summary>
113
+ /// <returns>Whether or not the instance is the type</returns>
114
+ public bool IsDictionaryHighlightResult ( )
115
+ {
116
+ return ActualInstance . GetType ( ) == typeof ( Dictionary < string , HighlightResult > ) ;
117
+ }
118
+
90
119
/// <summary>
91
120
/// Check if the actual instance is of `HighlightResultOption` type.
92
121
/// </summary>
@@ -100,7 +129,7 @@ public bool IsHighlightResultOption()
100
129
/// Check if the actual instance is of `Dictionary{string, HighlightResultOption}` type.
101
130
/// </summary>
102
131
/// <returns>Whether or not the instance is the type</returns>
103
- public bool IsDictionary ( )
132
+ public bool IsDictionaryHighlightResultOption ( )
104
133
{
105
134
return ActualInstance . GetType ( ) == typeof ( Dictionary < string , HighlightResultOption > ) ;
106
135
}
@@ -109,7 +138,7 @@ public bool IsDictionary()
109
138
/// Check if the actual instance is of `List{HighlightResultOption}` type.
110
139
/// </summary>
111
140
/// <returns>Whether or not the instance is the type</returns>
112
- public bool IsList ( )
141
+ public bool IsListHighlightResultOption ( )
113
142
{
114
143
return ActualInstance . GetType ( ) == typeof ( List < HighlightResultOption > ) ;
115
144
}
@@ -199,6 +228,18 @@ public override HighlightResult Read(ref Utf8JsonReader reader, Type typeToConve
199
228
var jsonDocument = JsonDocument . ParseValue ( ref reader ) ;
200
229
var root = jsonDocument . RootElement ;
201
230
if ( root . ValueKind == JsonValueKind . Object )
231
+ {
232
+ try
233
+ {
234
+ return new HighlightResult ( jsonDocument . Deserialize < Dictionary < string , HighlightResult > > ( JsonConfig . Options ) ) ;
235
+ }
236
+ catch ( Exception exception )
237
+ {
238
+ // deserialization failed, try the next one
239
+ System . Diagnostics . Debug . WriteLine ( $ "Failed to deserialize into Dictionary<string, HighlightResult>: { exception } ") ;
240
+ }
241
+ }
242
+ if ( root . ValueKind == JsonValueKind . Object )
202
243
{
203
244
try
204
245
{
0 commit comments