@@ -17,13 +17,17 @@ public static T JsonTo<T>(this Dictionary<string, string> map, string key)
17
17
/// <summary>
18
18
/// Get JSON string value converted to T
19
19
/// </summary>
20
- public static T Get < T > ( this Dictionary < string , string > map , string key , T defaultValue = default ( T ) )
20
+ public static T Get < T > ( this Dictionary < string , string > map , string key , T defaultValue = default )
21
21
{
22
+ if ( map == null )
23
+ return default ;
22
24
return map . TryGetValue ( key , out var strVal ) ? JsonSerializer . DeserializeFromString < T > ( strVal ) : defaultValue ;
23
25
}
24
26
25
27
public static T [ ] GetArray < T > ( this Dictionary < string , string > map , string key )
26
28
{
29
+ if ( map == null )
30
+ return TypeConstants < T > . EmptyArray ;
27
31
return map . TryGetValue ( key , out var value )
28
32
? ( map is JsonObject obj ? value . FromJson < T [ ] > ( ) : value . FromJsv < T [ ] > ( ) )
29
33
: TypeConstants < T > . EmptyArray ;
@@ -34,6 +38,8 @@ public static T[] GetArray<T>(this Dictionary<string, string> map, string key)
34
38
/// </summary>
35
39
public static string Get ( this Dictionary < string , string > map , string key )
36
40
{
41
+ if ( map == null )
42
+ return null ;
37
43
return map . TryGetValue ( key , out var strVal )
38
44
? JsonTypeSerializer . Instance . UnescapeString ( strVal )
39
45
: null ;
@@ -56,11 +62,11 @@ public static List<T> ConvertAll<T>(this JsonArrayObjects jsonArrayObjects, Func
56
62
return results ;
57
63
}
58
64
59
- public static T ConvertTo < T > ( this JsonObject jsonObject , Func < JsonObject , T > converFn )
65
+ public static T ConvertTo < T > ( this JsonObject jsonObject , Func < JsonObject , T > convertFn )
60
66
{
61
67
return jsonObject == null
62
- ? default ( T )
63
- : converFn ( jsonObject ) ;
68
+ ? default
69
+ : convertFn ( jsonObject ) ;
64
70
}
65
71
66
72
public static Dictionary < string , string > ToDictionary ( this JsonObject jsonObject )
0 commit comments