I have the interesting idea. I want to redefine the keywords in C#, like replace the if
keyword to the MyIf
or something else. Do someone have any idea about how to do it?
As I think it have to look something like this:
namespace
{
#define MyIf = if;
#define MyElse = else;
...
public someclass
{
public void someMethod()
{
MyIf(true)
{
...
}
MyElse
{
...
}
}
}
}
Added:
Maybe there is the way how to make the C++ or C library which will redefine the part of standard core of C#?
**Notice. I know that it is the bad programming practice and I ask all the programmers to not use the answer in your enterprise code. **
That's not possible -- C# does not have a preprocessor like C and C++ do, so there is no mechanism to transform the source before the compiler sees it. And of course the compiler will only recognize the standard if
, so there is also no other option that somehow transforming the source before the compiler sees it.
Even if it were possible, it would be just a step below Cthulhu in the horror scale.
In c# you can override the overloadable operators (+ , - , ==) more info here: http://msdn.microsoft.com/en-us/library/8edha89s(v=vs.80).aspx
But you can't really override conditional operators.
The same goes for these operators =, ., ?:, ->, new, is, sizeof, typeof, they cannot be overloaded.
C# does not support macros, but of course you could write a custom parser that handles macros before eventually sending your code to the c# compiler, take a look at Microsoft Roslyn for that.
http://msdn.microsoft.com/en-us/vstudio/roslyn.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With