forked from ln-dotnet/ln.json
26 lines
647 B
C#
26 lines
647 B
C#
|
using System;
|
|||
|
using ln.types.net;
|
|||
|
|
|||
|
namespace ln.json.mapping
|
|||
|
{
|
|||
|
public class JSONIPv4Mapping : JSONMapping
|
|||
|
{
|
|||
|
public JSONIPv4Mapping() : base(typeof(IPv4))
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
public override object FromJson(JSONMapper mapper, JSONValue json)
|
|||
|
{
|
|||
|
if (json is JSONNumber)
|
|||
|
{
|
|||
|
return new IPv4((uint)(((JSONNumber)json).Decimal));
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return IPv4.Parse(((JSONString)json).Value);
|
|||
|
}
|
|||
|
}
|
|||
|
public override JSONValue ToJson(JSONMapper mapper, object value) => new JSONString(value.ToString());
|
|||
|
}
|
|||
|
}
|