<div>On Mon, Oct 24, 2011 at 12:47 AM, Jacob Carlborg <span dir="ltr"><<a href="mailto:doob@me.com">doob@me.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<div><div></div><div class="h5"><br></div></div>You can foreach over ModuleInfo and access the classes using "localClasses". Have a look at the implementation of object.TypeInfo_Class.find in druntime.<br><font color="#888888"><br>
<br>-- <br>/Jacob Carlborg<br></font></blockquote></div><div><font class="Apple-style-span" color="#888888"><br></font></div><div><br></div><div>And here is the last piece of the puzzle:</div><div><br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;">
<div><font class="Apple-style-span" face="'courier new', monospace">void main(string[] args)</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> {</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> foreach(m; ModuleInfo)</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> {</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> //there are many modules, only choose what we're interested in</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> if (!startsWith(<a href="http://m.name">m.name</a>, "dt"))</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> {</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> continue;</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> }</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> writeln("==== module: ", <a href="http://m.name">m.name</a>);</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> foreach(c; m.localClasses)</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> {</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> //need to exclude Base </font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> if (!startsWith(<a href="http://c.name">c.name</a>, <a href="http://m.name">m.name</a> ~ ".X"))</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> {</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> continue;</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> }</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> writeln("==== class:", <a href="http://c.name">c.name</a>);</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> auto obj = Object.factory(<a href="http://c.name">c.name</a>);</font></div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace; "> }</span></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> }</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> }</font></div></blockquote><div><br></div>with the output:
<blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div><font class="Apple-style-span" face="'courier new', monospace">$ rm -f dtest; dmd dtest.d variant.d -ofdtest; ./dtest</font></div>
</div><div><div><font class="Apple-style-span" face="'courier new', monospace">==== module: dtest</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace">==== class:dtest.XBob</font></div>
</div><div><div><font class="Apple-style-span" face="'courier new', monospace">RunAllIn: dtest.XBob</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace">== i=2 m=inBob1</font></div>
</div><div><div><font class="Apple-style-span" face="'courier new', monospace"> in bob : inBob1()</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace">== i=3 m=inBob2</font></div>
</div><div><div><font class="Apple-style-span" face="'courier new', monospace"> in bob : inBob2()</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace">==== class:dtest.XJane</font></div>
</div><div><div><font class="Apple-style-span" face="'courier new', monospace">RunAllIn: dtest.XJane</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace">== i=1 m=inJane1</font></div>
</div><div><div><font class="Apple-style-span" face="'courier new', monospace"> in jane : inJane1()</font></div></div><div><div><font class="Apple-style-span" face="'courier new', monospace">== i=2 m=inJane2</font></div>
</div><div><div><font class="Apple-style-span" face="'courier new', monospace"> in jane : inJane2()</font></div></div></blockquote><div><br></div><div>Many thanks Jacob!</div><div><br></div><div>John</div>