From 64e3154ae3ed20f2a9d46bcd31963f10252a81e2 Mon Sep 17 00:00:00 2001 From: Argo-AscioTech Date: Mon, 14 Oct 2024 13:52:22 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=94=B9=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E7=A9=BA=E9=97=B4=E7=B2=BE=E7=AE=80=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Converter/JsonEnumConverter.cs | 31 ++++--------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/src/BootstrapBlazor/Converter/JsonEnumConverter.cs b/src/BootstrapBlazor/Converter/JsonEnumConverter.cs index 4e7564cfc86..d5e4fb35c64 100644 --- a/src/BootstrapBlazor/Converter/JsonEnumConverter.cs +++ b/src/BootstrapBlazor/Converter/JsonEnumConverter.cs @@ -10,29 +10,10 @@ namespace BootstrapBlazor.Core.Converter; /// /// JsonEnumConverter 枚举转换器 /// -public class JsonEnumConverter : JsonConverterAttribute +/// Optional naming policy for writing enum values. +/// True to allow undefined enum values. When true, if an enum value isn't defined it will output as a number rather than a string. +public class JsonEnumConverter(bool camelCase = false, bool allowIntegerValues = true) : JsonConverterAttribute { - /// - /// 构造函数 - /// - /// Optional naming policy for writing enum values. - /// True to allow undefined enum values. When true, if an enum value isn't defined it will output as a number rather than a string. - public JsonEnumConverter(bool camelCase = false, bool allowIntegerValues = true) - { - _camelCase = camelCase; - _allowIntegerValues = allowIntegerValues; - } - - /// - /// naming policy for writing enum values - /// - private readonly bool _camelCase; - - /// - /// True to allow undefined enum values. When true, if an enum value isn't defined it will output as a number rather than a string - /// - private readonly bool _allowIntegerValues; - /// /// /// @@ -40,9 +21,9 @@ public JsonEnumConverter(bool camelCase = false, bool allowIntegerValues = true) /// public override JsonConverter? CreateConverter(Type typeToConvert) { - var converter = _camelCase - ? new JsonStringEnumConverter(JsonNamingPolicy.CamelCase, _allowIntegerValues) - : new JsonStringEnumConverter(null, _allowIntegerValues); + var converter = camelCase + ? new JsonStringEnumConverter(JsonNamingPolicy.CamelCase, allowIntegerValues) + : new JsonStringEnumConverter(null, allowIntegerValues); return converter; } }