41 lines
965 B
C#
41 lines
965 B
C#
using System;
|
|
using Newtonsoft.Json.Linq;
|
|
using ln.types.net;
|
|
|
|
namespace ln.types.json.converter
|
|
{
|
|
public class JSONIPv4Converter : IJsonConvert
|
|
{
|
|
public JSONIPv4Converter()
|
|
{
|
|
}
|
|
|
|
public string GetSkyType(Type nativeType)
|
|
{
|
|
if (typeof(IPv4).Equals(nativeType))
|
|
return "ipv4";
|
|
return null;
|
|
}
|
|
|
|
public bool JSON2Value(Type targetType, JToken jToken, ref object value)
|
|
{
|
|
if (typeof(IPv4).Equals(targetType))
|
|
{
|
|
value = IPv4.Parse(jToken.ToObject<String>());
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public bool Value2JSON(object value, ref JToken jToken)
|
|
{
|
|
if (value is IPv4)
|
|
{
|
|
jToken = JToken.FromObject((value as IPv4).ToString());
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
}
|