You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

25 lines
708 B

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Wood.Util
{
public class NullableIntConverter: JsonConverter<int?>
{
public override int? ReadJson(JsonReader reader, Type objectType, int? existingValue, bool hasExistingValue, JsonSerializer serializer)
{
if ((reader.Value == null || reader.Value.ToString() == ""))
return 0;
return Convert.ToInt32(reader.Value);
}
public override void WriteJson(JsonWriter writer, int? value, JsonSerializer serializer)
{
writer.WriteValue(value);
}
}
}