| Partial classes are really useful |
Alex Hoffman comments that as best as he can determine partial classes are only useful for tool developers. That's not quite true.
Consider my current project. We have a COM SDK to our product which has something in the order of 80 first class objects, many (over a hundred?) enumerations, and a lot of methods. To get around the fairly massive amount of leg work which needed to be done to expose the relevant bits of that, I wrote a generator. The generator can take a enum (for example), and expose the values in the right way for a web service, with the right names, and arrange the casting back to the original COM data type when needed. Now, with Everett (Visual Studio 2003) I need to copy that code into the class which uses it using cut and paste. With partial classes it can sit in a file of generated bits, and the hand tooled parts of the class are elsewhere.
Now that I've done it for real, I've fallen in love with code generation. It meant that I could take a death march project and turn it into something much more relaxing in this instance, whilst knowing with greater certainty than before that everything really is exposed right and that I haven't missed an argument to a function or a enumeration entry. My boss wonders how come I am so efficient now I suspect.
I'll be using code generation techniques more in the future, and I'll therefore love partial classes when they come along.
posted at: 13:22 | path: /dotnet | permanent link to this entry
