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
35 lines
1.3 KiB
C#
35 lines
1.3 KiB
C#
using System;
|
|
using System.Reflection;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace MonoGame.Extended.Particles.Serialization;
|
|
|
|
/// <summary>
|
|
/// Converts a <see cref="ParticleModifierExecutionStrategy"/> value to or from JSON.
|
|
/// </summary>
|
|
public class ModifierExecutionStrategyJsonConverter : JsonConverter<ParticleModifierExecutionStrategy>
|
|
{
|
|
/// <inheritdoc />
|
|
public override bool CanConvert(Type typeToConvert) =>
|
|
typeToConvert == typeof(ParticleModifierExecutionStrategy) ||
|
|
typeToConvert.GetTypeInfo().BaseType == typeof(ParticleModifierExecutionStrategy);
|
|
|
|
/// <inheritdoc />
|
|
public override ParticleModifierExecutionStrategy Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
{
|
|
var value = JsonSerializer.Deserialize<string>(ref reader, options);
|
|
return ParticleModifierExecutionStrategy.Parse(value);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
/// <exception cref="ArgumentNullException">
|
|
/// Throw if <paramref name="writer"/> is <see langword="null"/>.
|
|
/// </exception>
|
|
public override void Write(Utf8JsonWriter writer, ParticleModifierExecutionStrategy value, JsonSerializerOptions options)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(writer);
|
|
writer.WriteStringValue(value.ToString());
|
|
}
|
|
}
|