mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-11-09 10:55:02 +08:00
style: clean code
This commit is contained in:
@@ -1,22 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text.Json;
|
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace System.Text.Json.Converters
|
|
||||||
{
|
|
||||||
internal class TextualBooleanConverter : JsonConverter<bool>
|
|
||||||
{
|
|
||||||
private readonly JsonConverter<bool?> _converter = new TextualNullableBooleanConverter();
|
|
||||||
|
|
||||||
public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
||||||
{
|
|
||||||
return _converter.Read(ref reader, typeToConvert, options) ?? default;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options)
|
|
||||||
{
|
|
||||||
_converter.Write(writer, value, options);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace System.Text.Json.Converters
|
|
||||||
{
|
|
||||||
internal class TextualNullableBooleanConverter : JsonConverter<bool?>
|
|
||||||
{
|
|
||||||
public override bool? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
||||||
{
|
|
||||||
if (reader.TokenType == JsonTokenType.Null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else if (reader.TokenType == JsonTokenType.True)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (reader.TokenType == JsonTokenType.False)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (reader.TokenType == JsonTokenType.String)
|
|
||||||
{
|
|
||||||
string? value = reader.GetString();
|
|
||||||
if (value == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
if ("true".Equals(value, StringComparison.OrdinalIgnoreCase))
|
|
||||||
return true;
|
|
||||||
else if ("false".Equals(value, StringComparison.OrdinalIgnoreCase))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new JsonException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Write(Utf8JsonWriter writer, bool? value, JsonSerializerOptions options)
|
|
||||||
{
|
|
||||||
if (value.HasValue)
|
|
||||||
writer.WriteStringValue(value.Value ? "true" : "false");
|
|
||||||
else
|
|
||||||
writer.WriteNullValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user