Does anyone think C#'s partial would have any use in D?

Rumbu rumbu at
Sun Dec 19 06:30:08 UTC 2021

On Sunday, 19 December 2021 at 04:24:30 UTC, Dr Machine Code 
> Does anyone thinks C# would benefit of having this keyword? I 
> think it was mostly implemented to make it easier the Visual 
> Studio's code generator. Can't think much of it. But give D 
> doesn't have even multiples inheritances, it's unlikely to be 
> appreciated but just like to know you all opinions

I suppose you wanted to say that D will benefit from it.

It was already discussed in the past, you can search the forum 
for it. The conclusion was that metaprogramming capabilities of D 
are enough to not mandate the use of partial classes.

partial class C
   //generated code

class C
   //custom code

can be achieved in D using mixins:

class C
   mixin!C //generated code
   //custom code

As a concrete example, you can browse the libdparse source code 
on github, especially ast.d code where the content of AST nodes 
is mostly generated by mixins.

An external tool like VS should generate the mixin content 
instead of class content.


Now back to the principle, partial classes will not work in D, 
because you cannot place a class in two different modules, their 
fully qualified name will be different.

More information about the Digitalmars-d mailing list