Tales from the Evil Empire

Bertrand Le Roy's blog


Bertrand Le Roy

BoudinFatal's Gamercard

Tales from the Evil Empire - Blogged

Blogs I read

My other stuff


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.



Joe Chung said:

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<string, string> 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. ;)

# September 24, 2007 8:08 PM

Christian Toivola said:

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

# September 26, 2007 12:46 PM

Bertrand Le Roy said:

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

# September 27, 2007 12:32 AM