mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
ThePirateBay: replace yml with c# and using TPB's API (#9593)
This commit is contained in:

committed by
GitHub

parent
00d3a62cf1
commit
977279318d
33
src/Jackett.Common/Converters/StringToLongConverter.cs
Normal file
33
src/Jackett.Common/Converters/StringToLongConverter.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Jackett.Common.Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// converts a string value to a long and vice-versa.
|
||||
/// </summary>
|
||||
public sealed class StringToLongConverter : JsonConverter
|
||||
{
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
=> writer.WriteValue(value.ToString());
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
if (reader.Value == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (reader.Value is long)
|
||||
{
|
||||
return reader.Value;
|
||||
}
|
||||
|
||||
return long.TryParse((string)reader.Value, out var foo)
|
||||
? foo
|
||||
: (long?) null;
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type objectType) => objectType == typeof(string);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user