Skip to content

Commit c07c234

Browse files
authored
refactor(JsonEnumConverter): update namespace (#4455)
1 parent f9f0934 commit c07c234

File tree

1 file changed

+6
-25
lines changed

1 file changed

+6
-25
lines changed

src/BootstrapBlazor/Converter/JsonEnumConverter.cs

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,20 @@ namespace BootstrapBlazor.Core.Converter;
1010
/// <summary>
1111
/// JsonEnumConverter 枚举转换器
1212
/// </summary>
13-
public class JsonEnumConverter : JsonConverterAttribute
13+
/// <param name="camelCase">Optional naming policy for writing enum values.</param>
14+
/// <param name="allowIntegerValues">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.</param>
15+
public class JsonEnumConverter(bool camelCase = false, bool allowIntegerValues = true) : JsonConverterAttribute
1416
{
15-
/// <summary>
16-
/// 构造函数
17-
/// </summary>
18-
/// <param name="camelCase">Optional naming policy for writing enum values.</param>
19-
/// <param name="allowIntegerValues">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.</param>
20-
public JsonEnumConverter(bool camelCase = false, bool allowIntegerValues = true)
21-
{
22-
_camelCase = camelCase;
23-
_allowIntegerValues = allowIntegerValues;
24-
}
25-
26-
/// <summary>
27-
/// naming policy for writing enum values
28-
/// </summary>
29-
private readonly bool _camelCase;
30-
31-
/// <summary>
32-
/// 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
33-
/// </summary>
34-
private readonly bool _allowIntegerValues;
35-
3617
/// <summary>
3718
/// <inheritdoc/>
3819
/// </summary>
3920
/// <param name="typeToConvert"></param>
4021
/// <returns></returns>
4122
public override JsonConverter? CreateConverter(Type typeToConvert)
4223
{
43-
var converter = _camelCase
44-
? new JsonStringEnumConverter(JsonNamingPolicy.CamelCase, _allowIntegerValues)
45-
: new JsonStringEnumConverter(null, _allowIntegerValues);
24+
var converter = camelCase
25+
? new JsonStringEnumConverter(JsonNamingPolicy.CamelCase, allowIntegerValues)
26+
: new JsonStringEnumConverter(null, allowIntegerValues);
4627
return converter;
4728
}
4829
}

0 commit comments

Comments
 (0)