I was trying to access dynamic property in Nancy. In Nancy if pass parameter in query it comes as dynamic property. How can I access that.
There are many discussion / question about this but every where, first it is of creating dynamic and then consuming it. How can I consume what is already created?
Here are two code snippet
public class ParameterModule : NancyModule
{
public ParameterModule():base("/{about}")
{
this.Get["/"] = (parameters) => "Hello About" + parameters.about;
}
}
and for F#
type ParameterModule() as this =
inherit NancyModule("/{about}")
do this.Get.["/"] <- fun parameters -> "Hello" + parameters?("about") :> obj
I can't access about as object don't have that property.
Please let me know if any further information needed.
The F# dynamic operator (?)
allows you to pass string parameters without using the quotes, achieving a similar syntax to C# dynamic, but you need to define it first for your concrete use case, the compiler just provides the syntax. Try this:
let (?) (parameters:obj) param =
(parameters :?> Nancy.DynamicDictionary).[param]
type ParameterModule() as this =
inherit NancyModule("/{about}")
do this.Get.["/"] <- fun parameters -> sprintf "Hello %O" parameters?about :> obj
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With