File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -18,15 +18,21 @@ public abstract class CustomDataBase
1818 /// <summary>
1919 /// Gets a custom data value parsed into <typeparamref name="T"/>
2020 /// </summary>
21- public T GetData < T > ( string name ) => GetDataInternal < T > ( name ) ;
21+ public T GetData < T > ( string name ) => GetData < T > ( name , null ) ;
22+
23+ /// <summary>
24+ /// Gets a custom data value parsed into <typeparamref name="T"/>
25+ /// If <paramref name="serializer"/> is not null, it will be used to de-serialize the value.
26+ /// </summary>
27+ public T GetData < T > ( string name , JsonSerializer serializer ) => GetDataInternal < T > ( name , serializer ) ;
2228
2329 /// <summary>
2430 /// Gets a custom data value parsed into <typeparamref name="T"/>.
2531 /// If it doesn't exist, it returns <paramref name="default"/>.
2632 /// </summary>
2733 public T GetDataOrDefault < T > ( string name , T @default ) => Data . TryGetValue ( name , out var val ) ? val . ToObject < T > ( ) : @default ;
2834
29- private T GetDataInternal < T > ( string name )
35+ private T GetDataInternal < T > ( string name , JsonSerializer serializer )
3036 {
3137 if ( Data . TryGetValue ( name , out var val ) )
3238 {
@@ -41,6 +47,11 @@ private T GetDataInternal<T>(string name)
4147 return StreamJsonConverter . DeserializeObject < T > ( val . Value < string > ( ) ) ;
4248 }
4349
50+ if ( serializer != null )
51+ {
52+ return val . ToObject < T > ( serializer ) ;
53+ }
54+
4455 return val . ToObject < T > ( ) ;
4556 }
4657
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ public static class StreamJsonConverter
1515 NullValueHandling = NullValueHandling . Ignore ,
1616 } ;
1717
18+ public static JsonSerializer Serializer { get ; } = JsonSerializer . Create ( Settings ) ;
1819 public static string SerializeObject ( object obj ) => JsonConvert . SerializeObject ( obj , Settings ) ;
1920 public static T DeserializeObject < T > ( string json ) => JsonConvert . DeserializeObject < T > ( json , Settings ) ;
2021 }
You can’t perform that action at this time.
0 commit comments