更新wtm

This commit is contained in:
zgf committed 2023-08-11 15:55:50 +08:00
1 parent f119665d29
commit 3467d4aa9d
60 files changed
+1932 -397

No files matched your search

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace WalkingTec.Mvvm.Core.Json
{
public class NullableConverter<T> : JsonConverter<Nullable<T>> where T : struct
{
public override T? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.String)
{
if (string.IsNullOrEmpty(reader.GetString()) || string.IsNullOrWhiteSpace(reader.GetString()))
{
return null;
}
else
{
return JsonSerializer.Deserialize<T>(ref reader, options);
}
}
return JsonSerializer.Deserialize<T>(ref reader, options);
}
public override void Write(Utf8JsonWriter writer, T? value, JsonSerializerOptions options)
{
JsonSerializer.Serialize(writer, value!.Value, options);
}
}
}