Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to add keyword to C# or VB.NET?

I know it might not be worth it but just for education purposes I want to know if there is a way to inject your own keywords to .NET languages.

For example I thought it's good to have C++ asm keyword in C#.
Remember I'm not talking about how to implement asm keyword but a general way to add keyword to C#.

My imagined code :

asm{
    mov ax,1
    add ax,4
}

So is there a way to achieve this ?
The answers which cover implementing keyword{ } suits enough for this question.

like image 277
Mohsen Sarkar Avatar asked Mar 13 '13 14:03

Mohsen Sarkar


1 Answers

This isn't possible at the moment. However, there's a Microsoft project in development called Roslyn that can be summarised as "the compiler as a service." It allows you, amongst other things, to extend or modify the behaviour of the compiler through an API.

When Roslyn becomes available, I believe this should be something that (with caution!) is quite doable.

like image 69
Dan Puzey Avatar answered Oct 12 '22 23:10

Dan Puzey