如何调整在南希模型绑定字段名?绑定、模型、字段名、南希

2023-09-04 09:45:48 作者:一颗心在瞬间死掉

在Web应用程序中我使用南希创建REST服务。不幸的是,我们的HTML字段名都是小写的(的firstName ),但在.NET中相应的属性是大写(名字 )。此外,我们有一些领域没有映射1:1,如 ID 这将成为 TicketId 研究。 NET。

现在我有两个问题,关于这一点:

是南希区分大小写或不区分大小写的,当涉及到字段名? 在南希是否提供某种映射的字段名称? 解决方案

支持,这是存在的,但它不是全功能的,我想。

周末随心飞,买卡到第一次出游 这一次我去敦煌

如果你看一下在 IFieldNameConverter 接口(它的默认实现 DefaultFieldNameConverter ),这就是处理转换字段名喜欢的事情外壳。

对于更复杂的映射,你就必须实施的 ITypeConverter ,你可能只是包装的默认转换器(S) - 这取决于你的数据 - 并调用默认的前更改输入

In a web application I use Nancy for creating a REST service. Unfortunately, in HTML our field names are lowercase (firstName), but the appropriate properties in .NET are uppercase (FirstName). Moreover, we have some fields that don't map 1:1, such as id that shall become TicketId in .NET.

Now I have two question on this:

Is Nancy case-sensitive or case-insensitive when it comes to field names? Does Nancy provide some sort of mapping for field names?

解决方案

Support for this is there, but it's not as fully featured as I'd like.

If you take a look at the IFieldNameConverter interface (it's default implementation is DefaultFieldNameConverter), that's what handles converting field names for things like casing.

For more complicated mappings you'd have to implement an ITypeConverter, you could just "wrap" the default converter(s) - depending on your data - and alter the input before calling the default one.