Spotify.NET/SpotifyAPI.Web/Models/Converters/DoubleToIntConverter.cs
Lewis-Fam 9dbd210a2f
Fixed issues #926, and #928. (#942)
* Fixed issues #926, and #928.
Added JsonConverter attributes to properties.

* Fixed complier warning CA1305
2024-02-10 11:03:22 +01:00

22 lines
552 B
C#

using System;
using System.Globalization;
using Newtonsoft.Json;
namespace SpotifyAPI.Web
{
public class DoubleToIntConverter : JsonConverter<int>
{
public override void WriteJson(JsonWriter? writer, int value, JsonSerializer serializer)
{
writer?.WriteValue(value);
}
public override int ReadJson(JsonReader? reader, Type objectType, int existingValue, bool hasExistingValue,
JsonSerializer serializer)
{
return reader != null ? Convert.ToInt32(reader.Value, CultureInfo.InvariantCulture) : 0;
}
}
}