mirror of
http://git.xinwangdao.com/cnnc-embedded-parts-detect/detect.git
synced 2025-06-24 13:34:13 +08:00
26 lines
779 B
C#
26 lines
779 B
C#
![]() |
using System;
|
|||
|
using System.Text.Json;
|
|||
|
using System.Text.Json.Serialization;
|
|||
|
|
|||
|
namespace detect.gui.Converters;
|
|||
|
|
|||
|
public class JsonDateTimeConverter : JsonConverter<DateTime>
|
|||
|
{
|
|||
|
private readonly string _dateTimeFormat;
|
|||
|
|
|||
|
public JsonDateTimeConverter(string dateTimeFormat)
|
|||
|
{
|
|||
|
_dateTimeFormat = dateTimeFormat;
|
|||
|
}
|
|||
|
|
|||
|
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|||
|
{
|
|||
|
// 反序列化逻辑(如果需要)
|
|||
|
return DateTime.Parse(reader.GetString() ?? throw new InvalidOperationException());
|
|||
|
}
|
|||
|
|
|||
|
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
|
|||
|
{
|
|||
|
writer.WriteStringValue(value.ToString(_dateTimeFormat));
|
|||
|
}
|
|||
|
}
|