I'm aware that this is a rather broad question, but here it goes anyway...

What is, in your opinion, the most practical way to create own C# implementation with minor additions to the existing 4.0 feature set?

For context: I'm thinking about adding a couple of (mostly syntactic) niceties to the dynamic feature set that would improve the whole duck-typing experience. For example, these would include the idea of a dynamic interface, as proposed in this debate (particularly in the last comment from MiddleTommy).

I'm aware that nothing is stopping me from simply diving into the Mono sources. However, I'm compelled to first ask about potentially similar projects that may already exist in the wild. Any such extension efforts underway?


Take a look at the Nemerle programming language - it provides a C# front-end (built upon Nemerle.Peg), which is easily extensible. The only feature missing from its implementation of C# 4.0 is goto.


It is possible to do something like what the linked blog post describes with C# 4.0. You can subclass DynamicObject (or even ExpandoObject to have a good starting point) and override TryGetMember and the likes to forward the calls. Then, create a dynamic proxy for the dynamic object. There are several libraries for this purpose, one of them is impromptu-interface. Then you can say something like:

var obj = Impromptu.ActLike<ISomeInterface>(dyn_obj);

And you get a reference with IntelliSense support and ActLike<> will also check the availability of the members of the interface.


I don't think you even need to modify the compiler to get very close to dynamic interface.

Just create a wrapper class (possibly autogenerated) that dynamically forwards method invocations to the underlying object.

This has some disadvantages when compared with true dynamic interface, but should be much easier to implement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.