Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
FSharpOptionConverter.cs
Go to the documentation of this file.
3
5
6internal sealed class FSharpOptionConverter<TOption, TElement> : JsonConverter<TOption> where TOption : class
7{
9
11
13
15
17
18 internal override Type ElementType => typeof(TElement);
19
20 public override bool HandleNull => true;
21
22 [RequiresUnreferencedCode("Uses Reflection to access FSharp.Core components at runtime.")]
31
33 {
34 if (!state.IsContinuation && reader.TokenType == JsonTokenType.Null)
35 {
36 value = null;
37 return true;
38 }
39 state.Current.JsonPropertyInfo = state.Current.JsonTypeInfo.ElementTypeInfo.PropertyInfoForTypeInfo;
40 if (_elementConverter.TryRead(ref reader, typeof(TElement), options, ref state, out var value2))
41 {
43 return true;
44 }
45 value = null;
46 return false;
47 }
48
50 {
51 if (value == null)
52 {
53 writer.WriteNullValue();
54 return true;
55 }
57 state.Current.DeclaredJsonPropertyInfo = state.Current.JsonTypeInfo.ElementTypeInfo.PropertyInfoForTypeInfo;
59 }
60
62 {
63 if (value == null)
64 {
65 writer.WriteNullValue();
66 return;
67 }
70 }
71
73 {
74 if (reader.TokenType == JsonTokenType.Null)
75 {
76 return null;
77 }
79 return _optionConstructor(arg);
80 }
81}
override TOption Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
override bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, ref ReadStack state, out TOption value)
override void Write(Utf8JsonWriter writer, TOption value, JsonSerializerOptions options)
override bool OnTryWrite(Utf8JsonWriter writer, TOption value, JsonSerializerOptions options, ref WriteStack state)
FSharpOptionConverter(JsonConverter< TElement > elementConverter)
bool TryWrite(Utf8JsonWriter writer, in T value, JsonSerializerOptions options, ref WriteStack state)
bool TryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, ref ReadStack state, out T value)
T? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)