Introspection/Reflection/etc on Linux
J Arrizza
cppgent0 at gmail.com
Fri Nov 4 00:07:17 PDT 2011
On Mon, Oct 24, 2011 at 12:47 AM, Jacob Carlborg <doob at me.com> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20111104/39ddc4a9/attachment.html>
More information about the Digitalmars-d
mailing list