mirror of
https://github.com/snltty/linker.git
synced 2025-10-09 02:50:12 +08:00
20 lines
599 B
C#
20 lines
599 B
C#
using System;
|
|
using System.Net;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace Linker.Libs.JsonConverters
|
|
{
|
|
public sealed class IPAddressJsonConverter : JsonConverter<IPAddress>
|
|
{
|
|
public override IPAddress Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
{
|
|
return IPAddress.Parse(reader.GetString());
|
|
}
|
|
public override void Write(Utf8JsonWriter writer, IPAddress value, JsonSerializerOptions options)
|
|
{
|
|
writer.WriteStringValue(value.ToString());
|
|
}
|
|
}
|
|
}
|