Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to adjust field names in Nancy model bindings?

Tags:

.net

nancy

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:

  1. Is Nancy case-sensitive or case-insensitive when it comes to field names?
  2. Does Nancy provide some sort of mapping for field names?
like image 770
Golo Roden Avatar asked Sep 13 '13 07:09

Golo Roden


1 Answers

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.

like image 120
Steven Robbins Avatar answered Nov 07 '22 17:11

Steven Robbins