Sebastian Piu
Sebastian Piu

Reputation: 8008

Extending C# language?

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

Upvotes: 7

Views: 1867

Answers (4)

Onkelborg
Onkelborg

Reputation: 3997

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

Upvotes: 4

Henk Holterman
Henk Holterman

Reputation: 273274

There is nothing built-in.

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

Upvotes: 4

Jordão
Jordão

Reputation: 56477

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.

Upvotes: 8

Related Questions