BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Dynamic C# in Action

Dynamic C# in Action

Leia em Português

This item in japanese

Bookmarks

REST-style web service calls have a significant advantage over SOAP based ones in that they do not require tooling support. This makes them particularly easy to call from languages such as Ruby or Python. Unfortunately, the same cannot be said for C#, where the lack of tooling works against the developer.

The reason for this difference is dynamic typing. Languages like Ruby and Python can turn JSON and XML-based results directly into an object model. This can then be accessed using each languages standard method and property syntax. For languages like C#, no such mapping is possible without knowing ahead of time what they object graph is going to look like. This involves a tedious and error-prone process of hand-coding the necessary classes and parsing logic.

With C# 4, all this goes away. By combining it with Nikhil Kothari's Dynamic Rest project, C# and VB developers can get the same clean syntax that the dynamic programmers have come to expect. Since it is based on the early preview, there are some limitations,

Note that in the CTP, there isn't any support for indexers used against dynamic types, which gets in the way of normal array syntax. Hence the workaround above using Item(). However, I've been told, that support for indexing into dynamic types already exists in later builds.

In a follow-up post Nikhil demonstrates using C# 4 to call Amazon and Flickr services.

Rate this Article

Adoption
Style

BT