views:

249

answers:

4

Basically what I would like to know is if there is any way to add new 'statements' to the .net based languages? An example of what I'm looking for would be something like introducing a public class MyClass decoratorOf ClassWithLotsOfMethods and in pre-compile time changing that to be a normal class that overrides everything by default but the methods I define.

Another example would be the .net 3.5 auto properties, or extension methods, etc

This is just for fun, not that I really want to do this, just curious if is possible

Thanks! Seba

+8  A: 

C# doesn't allow this. You can of course tweak the generated IL with a post-compiler (like CciSharp).

Some alternative .NET languages that allow extensions are Nemerle and Boo.

Jordão
+5  A: 

There is nothing built-in.

You could of course use a PreProcessor but that won't make you popular.

Henk Holterman
Yeah, look at Simula -- all they did was invent object-oriented programming. Or C++ -- that's not very popular, is it? :-)
Ken
@Ken: how would adding a pre-processor make him popular? And what does this have to do with Simula (which was not actually an extension of ALGOL)?
John Saunders
I see no reason to believe the use of a preprocessor would have any particular effect on one's popularity, as there are good examples of extreme popularity and unpopularity both with and without one. And (if a dozen separate histories I found on the internet are to be believed) Simula started life as a preprocessor for Algol (as C++ started life as a preprocessor for C), though (like C++) it shortly took on a life of its own.
Ken
+3  A: 

Not that I know about, but take a look at PostSharp and T4 Templates and see if that can solve your problem :)

Onkelborg
I've built decorators with T4 before. It worked well, and didn't require anything extra to be installed
Rob Fonseca-Ensor
T4 would be my first option.
Jeff Yates