Fre*_*rke 4 graphql asp.net-core hotchocolate
FooBarHotChocolate 以所有大写蜗牛大小写序列化枚举值,这导致 Hot Chocolate推断出枚举值FOO_BAR,但value.ToString()给出Enum.GetName(value)FooBar,而 Hot Chocolate 似乎忽略了[EnumMember(Value = "FooBar")]。
如何将序列化更改为我想要的任何方式?
Fre*_*rke 10
HotChocolate 服务器 v11 遵循规范建议,默认将枚举值序列化为 UPPER_SNAIL_CASE。
你可以这样改变:
builder
.AddConvention<INamingConventions>(new YourNamingConvention())
Run Code Online (Sandbox Code Playgroud)
public class YourNamingConvention
: DefaultNamingConventions
{
public override NameString GetEnumValueName(object value)
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
return value.ToString().ToUpperInvariant(); // change this to whatever you like
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2988 次 |
| 最近记录: |