mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-15 15:09:29 +00:00
d008b1bd41
* Converted to use `System.Text.Json` * Remove Newtonsoft.Json Dependency Newtonsoft.Json dependency has been removed in favor of System.Text.Json * Treat MGFXO file as binary
33 lines
1.1 KiB
C#
33 lines
1.1 KiB
C#
using System;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace MonoGame.Extended.Gui.Serialization;
|
|
|
|
public class VerticalAlignmentConverter : JsonConverter<VerticalAlignment>
|
|
{
|
|
/// <inheritdoc />
|
|
public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(VerticalAlignment);
|
|
|
|
/// <inheritdoc />
|
|
public override VerticalAlignment Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
{
|
|
var value = reader.GetString();
|
|
|
|
if (value.Equals("Center", StringComparison.OrdinalIgnoreCase) || value.Equals("Centre", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return VerticalAlignment.Centre;
|
|
}
|
|
|
|
if (Enum.TryParse<VerticalAlignment>(value, true, out var alignment))
|
|
{
|
|
return alignment;
|
|
}
|
|
|
|
throw new InvalidOperationException($"Invalid value for '{nameof(VerticalAlignment)}'");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override void Write(Utf8JsonWriter writer, VerticalAlignment value, JsonSerializerOptions options) { }
|
|
}
|