Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 5 down vote accepted

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.

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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