JSON-style dictionary parameters in C#?

Eilon has an interesting post about using the new anonymous object initializer syntax in APIs that take dictionaries. The end result looks very much like the JSON parameterized function calls that are very common in many JavaScript frameworks, which shows once more how C# is getting many of the nice features of dynamic languages while remaining statically-typed. While I wouldn't use that just to get named parameters like those frameworks are often doing, it looks well-justified in this context because the parameter it's being used for is actually not predetermined.



  • It's JSON-like syntactically but not as flexible as JSON. You can neatly nest JSON within JSON, for instance. Nesting object-initialized anonymous types, on the other hand, sounds like it could get pretty messy, syntactically speaking.

    For a IDictionary parameter, JSON is overkill, but it's a nice substitute for XML, especially in Web browsers where XML support is spotty and inconsistent *cough* where's E4X, IE? *cough*.

    I'm just waiting for some standards body to come along and ruin the party for us all by coming up with some JSON-Schema specification. ;)

  • Are you referring to parameter currying? similar to passing in a hash (more or less)?

  • Christian: not quite currying, but passing a hash, yes.

Comments have been disabled for this content.