punish v6.8.18.0
This commit is contained in:
commit
e786325cda
322 changed files with 554232 additions and 0 deletions
|
@ -0,0 +1,57 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Questionable.Model.Common;
|
||||
|
||||
namespace Questionable.Model.Questing.Converter;
|
||||
|
||||
public sealed class AethernetShortcutConverter : JsonConverter<AethernetShortcut>
|
||||
{
|
||||
private static readonly Dictionary<EAetheryteLocation, string> EnumToString = AethernetShardConverter.Values;
|
||||
|
||||
private static readonly Dictionary<string, EAetheryteLocation> StringToEnum = EnumToString.ToDictionary<KeyValuePair<EAetheryteLocation, string>, string, EAetheryteLocation>((KeyValuePair<EAetheryteLocation, string> x) => x.Value, (KeyValuePair<EAetheryteLocation, string> x) => x.Key);
|
||||
|
||||
public override AethernetShortcut Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType != JsonTokenType.StartArray)
|
||||
{
|
||||
throw new JsonException();
|
||||
}
|
||||
if (!reader.Read() || reader.TokenType != JsonTokenType.String)
|
||||
{
|
||||
throw new JsonException();
|
||||
}
|
||||
string key = reader.GetString() ?? throw new JsonException();
|
||||
if (!reader.Read() || reader.TokenType != JsonTokenType.String)
|
||||
{
|
||||
throw new JsonException();
|
||||
}
|
||||
string key2 = reader.GetString() ?? throw new JsonException();
|
||||
if (!reader.Read() || reader.TokenType != JsonTokenType.EndArray)
|
||||
{
|
||||
throw new JsonException();
|
||||
}
|
||||
AethernetShortcut aethernetShortcut = new AethernetShortcut();
|
||||
if (!StringToEnum.TryGetValue(key, out var value))
|
||||
{
|
||||
throw new JsonException();
|
||||
}
|
||||
aethernetShortcut.From = value;
|
||||
if (!StringToEnum.TryGetValue(key2, out var value2))
|
||||
{
|
||||
throw new JsonException();
|
||||
}
|
||||
aethernetShortcut.To = value2;
|
||||
return aethernetShortcut;
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, AethernetShortcut value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStartArray();
|
||||
writer.WriteStringValue(EnumToString[value.From]);
|
||||
writer.WriteStringValue(EnumToString[value.To]);
|
||||
writer.WriteEndArray();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue