Custom key words and statements in C#, possible?

  • Thread starter Thread starter SpotNet
  • Start date Start date
S

SpotNet

Hello NewsGroup,

More curiosity than actuality for now anyway, just wanted to ask if it's
possible to extend C# by creating custom made key words and statements? If
it is possible, what would I have to consider if I wanted to build a
customised object for loop? Being the foreach loop in 'reverse'. Example;

private MyClassCollection mccol = new MyClassCollection();

mccol.Refresh();

forall (this.mccol on MyClass myclass)
{
//Do stuff the other way....
}

The custom key words being 'forall' and 'on'. More technical curiosity than,
why would I want to do that for?

Regards,
SpotNet
 
SpotNet said:
More curiosity than actuality for now anyway, just wanted to ask if it's
possible to extend C# by creating custom made key words and statements?

Not with the normal C# compiler. If you write your own compiler (or
extend the Mono one, for example) you can make it do whatever you like.
 
Thank you very much Jon, now that you've told me what's involved I really
don't think I'll be taking things that far.

Thanks again.

Regards,
SpotNet.

| > More curiosity than actuality for now anyway, just wanted to ask if it's
| > possible to extend C# by creating custom made key words and statements?
|
| Not with the normal C# compiler. If you write your own compiler (or
| extend the Mono one, for example) you can make it do whatever you like.
|
| --
| Jon Skeet - <[email protected]>
| http://www.pobox.com/~skeet
| If replying to the group, please do not mail me too
 
You can't modify the language, but if you want to make a loop that does
something different, all you have to do is create a wrapper class and
define GetEnumerator() for it to return an IEnumerator that gives you
back the things you want to loop over.

True, the syntax probably won't be as nice as you'd like it to be, but
by implementing IEnumerator and IEnumerable you can do pretty-much
anything you like.
 
Thanks Bruce, I can see myself spending half a year doing so, think I'll
push that one one to the Product Wish List Department.

Regards,
SpotNet.

| You can't modify the language, but if you want to make a loop that does
| something different, all you have to do is create a wrapper class and
| define GetEnumerator() for it to return an IEnumerator that gives you
| back the things you want to loop over.
|
| True, the syntax probably won't be as nice as you'd like it to be, but
| by implementing IEnumerator and IEnumerable you can do pretty-much
| anything you like.
|
 
Back
Top