using Newtonsoft.Json;
using System;
using System.Net;

namespace VCommon.Json
{
    /// <summary> 将 System.Net.EndPoint 以ToString方式序列化到Json,避免发生异常 </summary>
    public class EndPointConverter : JsonConverter<EndPoint>
    {
        public override bool CanRead => false;
        public override bool CanWrite => true;

        public override EndPoint ReadJson(JsonReader reader, Type objectType, EndPoint existingValue, bool hasExistingValue, JsonSerializer serializer) => throw new NotImplementedException();

        public override void WriteJson(JsonWriter writer, EndPoint value, JsonSerializer serializer) => writer.WriteValue(value?.ToString());
    }
}
