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
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.
There is nothing built-in.
You could of course use a PreProcessor but that won't make you popular.
Not that I know about, but take a look at PostSharp and T4 Templates and see if that can solve your problem :)
Related: Extending the Mono C# compiler: is there any documentation or precedent?
精彩评论