mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 11:26:27 +00:00
Data model conditions - Moved events into a separate 'mode'
This commit is contained in:
1 parent
e1eb03667e
commit
997ab005d8
26 files changed
+331
-128
No files matched your search
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Artemis.Core.JsonConverters
|
||||
{
|
||||
/// <summary>
|
||||
/// An int converter that, if required, will round float values
|
||||
/// </summary>
|
||||
internal class ForgivingIntConverter : JsonConverter<int>
|
||||
{
|
||||
public override bool CanWrite => false;
|
||||
|
||||
public override void WriteJson(JsonWriter writer, int value, JsonSerializer serializer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override int ReadJson(JsonReader reader, Type objectType, int existingValue, bool hasExistingValue, JsonSerializer serializer)
|
||||
{
|
||||
JValue jsonValue = serializer.Deserialize<JValue>(reader);
|
||||
|
||||
if (jsonValue.Type == JTokenType.Float)
|
||||
return (int) Math.Round(jsonValue.Value<double>());
|
||||
if (jsonValue.Type == JTokenType.Integer)
|
||||
return jsonValue.Value<int>();
|
||||
|
||||
throw new FormatException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user