On Mon, Oct 24, 2011 at 12:47 AM, Jacob Carlborg <[email protected]> wrote:
>
> You can foreach over ModuleInfo and access the classes using
> "localClasses". Have a look at the implementation of
> object.TypeInfo_Class.find in druntime.
>
>
> --
> /Jacob Carlborg
>
And here is the last piece of the puzzle:
void main(string[] args)
{
foreach(m; ModuleInfo)
{
//there are many modules, only choose what we're interested in
if (!startsWith(m.name, "dt"))
{
continue;
}
writeln("==== module: ", m.name);
foreach(c; m.localClasses)
{
//need to exclude Base
if (!startsWith(c.name, m.name ~ ".X"))
{
continue;
}
writeln("==== class:", c.name);
auto obj = Object.factory(c.name);
}
}
}
with the output:
$ rm -f dtest; dmd dtest.d variant.d -ofdtest; ./dtest
==== module: dtest
==== class:dtest.XBob
RunAllIn: dtest.XBob
== i=2 m=inBob1
in bob : inBob1()
== i=3 m=inBob2
in bob : inBob2()
==== class:dtest.XJane
RunAllIn: dtest.XJane
== i=1 m=inJane1
in jane : inJane1()
== i=2 m=inJane2
in jane : inJane2()
Many thanks Jacob!
John