partial class
Benji Smith
dlanguage at benjismith.net
Sat Nov 1 16:16:37 PDT 2008
Ary Borenszweig wrote:
> Alexander Pánek escribió:
>> You can’t just “monkey-patch” the original class, though. With partial
>> classes you could just inject some additional code to the original class.
>
> The thing is, in C# all pieces of a partial class must be defined in the
> same assembly, and it also must be defined as "partial class". So if you
> can "monkey-patch" a partial class, you could just as easily go to the
> class' source code and inject that additional code.
Although C# partial classes must be defined in the same assembly, you
can also use "extension methods" for adding new methods to an
already-defined class, no matter what assembly it comes from. Even the
core classes, like String, can be modified using extension methods.
The D trick where "static method(a, b)" is the same as "a.method(b)" is
almost identical to the C# extension methods. The only real difference
is that the trick can only be used on functions defined as extension
methods, not for any arbitrary function. I like that.
--benji
More information about the Digitalmars-d
mailing list