mirror of
https://github.com/ckaczor/ChrisKaczor.FeverClient.git
synced 2026-02-16 18:46:43 -05:00
Initial commit
This commit is contained in:
25
Converters/BoolConverter.cs
Normal file
25
Converters/BoolConverter.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ChrisKaczor.FeverClient.Converters
|
||||
{
|
||||
public class BoolTimestampConverter : JsonConverter<bool>
|
||||
{
|
||||
public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType != JsonTokenType.Number)
|
||||
{
|
||||
throw new JsonException("Expected a numeric boolean value");
|
||||
}
|
||||
|
||||
var number = reader.GetInt64();
|
||||
return number == 1;
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options)
|
||||
{
|
||||
var number = value ? 1 : 0;
|
||||
writer.WriteNumberValue(number);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user