ModuleInfo, Object.localClasses(), and Object.find() - any users?
cc
cc at nevernet.com
Mon Dec 12 21:49:41 UTC 2022
On Monday, 12 December 2022 at 20:58:40 UTC, Walter Bright wrote:
> I'm curious as to the reason it was being used.
This was an older project ported from Objective-C that read
external definition data, looking at it now it can (and probably
should) be replaced. The allowed class list still needed to be
verified so it's the same issue of explicitly registering
classes, so disregard that example.
In newer stuff I have RPC and serialization/remote object
duplication libraries where I explicitly register modules to scan
for classes by UDA (or have them indirectly register their own
modules when one class calls in to the library). It would be
nice to be able to preemptively scan/register classes in
arbitrary modules without needing to list them in a second area
of code. One (minor) example I have is a toString(OutputRange)()
promoter that calls the correct templated function when the
variable type doesn't match the typeid. This *doesn't* use
ModuleInfo, but it could. If derived classes exist across
multiple files, it can miss registering some of them if they call
out of order. Otherwise I need to explicitly register each class
I want handled here, which is the same "make one change in
multiple places" problem that avoiding is one of my favorite
strengths of D.
tl;dr I can live without it, but now that I'm reminded it exists,
it seems like a nice thing to have. 😕
More information about the Digitalmars-d
mailing list