wabbajack/Wabbajack/Converters/PercentJsonConverter.cs
2020-02-07 23:45:45 -06:00

24 lines
709 B
C#

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);
}
}
}