-
Notifications
You must be signed in to change notification settings - Fork 0
Taking a look at the DynamicDictionary
The DynamicDictionary is a dynamic type with dictionary-like behaviors, but there is a lot more to it under the covers and it's a big part of what helps Nancy provide a terse syntax in many places. The most obvious place, is in the lambda expression that forms the route action. Any captured values from the request will be put into a DynamicDictionary and passed into the action for the route.
With the DynamicDictionary you are able to access the values using a standard indexer approach or by using the name, of the captured, value just as a normal property. Both produce the same result, it all comes down to personal preference.
Get["/hello/{name}"] = parameters => {
return "Hello " + parameters.name;
};
Get["/goodbye/{name}"] = parameters => {
return "Goodbye " + parameters["name"];
};It is worth noting that if you prefer accessing captured properties via a normal property you must assign the capture group a valid C# identifier (i.e.: one that starts with an alphabetic character).
The stored values can explicitly or implicitly be cast to most of the primitive types and a special property, called HasValue can be checked to determine if a value has been assigned or not. The values also implement the IEquatable<> and IConvertible interfaces.
[<< Part 3. Defining routes](Defining routes) - Documentation overview - [Part 5. The before and after module hooks >>](The before and after module hooks)
- Taking a look at the DynamicDictionary
- The before and after module hooks
- Model binding
- Bootstrapper
- View Engines
- View location conventions
- Testing your application
- The root path
- Managing static content
- Diagnostics
- Adding a custom FavIcon
- The Application Before, After and OnError pipelines
- Generating a custom error page
- The cryptography helpers
- Content negotiation
- Authentication
- More to come
- Hosting Nancy with ASP.NET
- Hosting Nancy with WCF
- Hosting Nancy with Azure
- Hosting Nancy with OWIN
- Hosting Nancy with Umbraco
- Hosting Nancy with Nginx on Ubuntu
- Self Hosting Nancy
- Implementing a Host
- Accessing the client certificate when using SSL
- Blog Posts, Video & Audio
- Async-Beta (Async Beta)