Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
FSharpValueOptionConverter.cs
Go to the documentation of this file.
3
5
6internal sealed class FSharpValueOptionConverter<TValueOption, TElement> : JsonConverter<TValueOption> where TValueOption : struct, IEquatable<TValueOption>
7{
9
10 private readonly FSharpCoreReflectionProxy.StructGetter<TValueOption, TElement> _optionValueGetter;
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 = default(TValueOption);
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 = default(TValueOption);
46 return false;
47 }
48
50 {
51 if (value.Equals(default(TValueOption)))
52 {
53 writer.WriteNullValue();
54 return true;
55 }
57 state.Current.DeclaredJsonPropertyInfo = state.Current.JsonTypeInfo.ElementTypeInfo.PropertyInfoForTypeInfo;
59 }
60
62 {
63 if (value.Equals(default(TValueOption)))
64 {
65 writer.WriteNullValue();
66 return;
67 }
70 }
71
73 {
74 if (reader.TokenType == JsonTokenType.Null)
75 {
76 return default(TValueOption);
77 }
79 return _optionConstructor(arg);
80 }
81}
override void Write(Utf8JsonWriter writer, TValueOption value, JsonSerializerOptions options)
readonly FSharpCoreReflectionProxy.StructGetter< TValueOption, TElement > _optionValueGetter
override bool OnTryWrite(Utf8JsonWriter writer, TValueOption value, JsonSerializerOptions options, ref WriteStack state)
override bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, ref ReadStack state, out TValueOption value)
override TValueOption Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
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)