[antlr-interest] Use partial classes for C#

Dr. Hartmut Kocher hwk.cortex-brainware at t-online.de
Wed Mar 28 08:01:04 PDT 2007

Hi Robert, 

Well, I don't quite agree (well I agree that there might be more important
things to do first):

The point is that partial classes are generated in different files.
Therefore, regenerating means that you can simply discard the generated file
and regenerate it as your manual changes are in a different file.

Regions on the other hand are generated into one file. Therefore, if you
manually added something, you must be careful during regeneration to
preserve your manual changes. This was a problem in .NET 1. That's the whole
reason why partial classes were introduced in .NET 2.0.

This has been proven to be useful. So why not use it?


Dr. Hartmut Kocher

-----Ursprüngliche Nachricht-----
Von: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] Im Auftrag von Hill, Robert
Gesendet: Mittwoch, 28. März 2007 16:09
An: antlr-interest at antlr.org
Betreff: Re: [antlr-interest] Use partial classes for C#

Hi All, 
	I'd like to see partial classes (but...I'd like to see the C#
uptodate first ;)  ) but partial classes do allow you to organise your code
more easily - marginally.
For the really fussy you can just surround the offensive code with #region -
#endregion and then collapse it.
Inheritance implies some kind of relationship that partials don't, they just
split the definition across multiple files for convenience. It's a nice
feature of .Net I have to agree. But it's not *that* essential. Prior to 2.0
the standard was to surround the code with #region which you can do by hand
anyway if you're desperate.

Robert Hill
>-----Original Message-----
>From: antlr-interest-bounces at antlr.org 
>[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Dr. 
>Hartmut Kocher
>Sent: 28 March 2007 14:58
>To: 'Martin Probst'
>Cc: antlr-interest at antlr.org
>Subject: Re: [antlr-interest] Use partial classes for C#
>Of course, this is how I do it for now. However, partial 
>classes were invented for exactly this reason: Mix generated 
>and hand written code in one class but in different files. 
>ASP.NET / WinForms etc. do it and a whole bunch of other 
>generators do it as well. This is the standard way of 
>generating code in the .NET world.
>So I think ANTLR should follow this.
>Dr. Hartmut Kocher

More information about the antlr-interest mailing list