wabbajack/Wabbajack/Converters/PercentJsonConverter.cs

24 lines
709 B
C#
Raw Normal View History

2020-02-08 04:35:08 +00:00
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using Newtonsoft.Json;
using Wabbajack.Common;
namespace Wabbajack
{
public class PercentJsonConverter : JsonConverter<Percent>
{
public override Percent ReadJson(JsonReader reader, Type objectType, [AllowNull] Percent existingValue, bool hasExistingValue, JsonSerializer serializer)
{
double d = (double)reader.Value;
return Percent.FactoryPutInRange(d);
}
public override void WriteJson(JsonWriter writer, [AllowNull] Percent value, JsonSerializer serializer)
{
writer.WriteValue(value.Value);
}
}
}