Partial classes
Regan Heath
regan at netmail.co.nz
Mon Jun 25 09:04:27 PDT 2012
On Mon, 25 Jun 2012 16:26:27 +0100, Manu <turkeyman at gmail.com> wrote:
> I suspect this isn't possible in a compiled language like D, but I wonder
> anyway, has anyone considered partial classes in D? Are they technically
> possible?
> How would they work? Would it depend on link-time code generation?
> I can imagine an implementation where each 'part' occupies a separate
> allocation, and some pointer in Object or somewhere like that (somewhere
> near the typeinfo pointer) binds them together.
>
> I often find myself wanting to add some extra pizazz to classes using
> template/mixin magic, but I may not have control over the original code
> where it is defined...
> C# at least can do this, and it's very useful in many situations...
I thought that the various parts of partial classes in C# had to be
compiled together. For example, I once tried to put a partial class into
a C# dll, and the rest in a C# executable using that first dll and it just
plain wont let you do this.
However, the c# code generated for me by sqlmetal produces a partial class
derived from a DataContext (in one file), which I can extend and/or modify
by implementing the rest of the partial class (in another file), in the
same project (exe or dll) and if I compile them together I actually just
get one merged class.
D could easily implement a partial class feature with the restriction that
they need to be compiled together. But IMO unless this is a trivial
feature to implement, I wouldn't think it would be high on the priority
list just yet.
Partial classes make customizing auto generated (especially repeatedly
auto generated) code much easier. #c uses them in it's form designer,
placing all the designed code in a partial class in one file, and all user
code in another file (in the same partial class).
R
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
More information about the Digitalmars-d
mailing list