<br><br><div class="gmail_quote">On Wed, Sep 1, 2010 at 15:25, Simen kjaeraas <span dir="ltr">&lt;<a href="mailto:simen.kjaras@gmail.com">simen.kjaras@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">Philippe Sigaud &lt;<a href="mailto:philippe.sigaud@gmail.com" target="_blank">philippe.sigaud@gmail.com</a>&gt; wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
I also have a template that gets the list of all members of an aggregate<br>
type (classes, structs and, well, modules, in a way), even the constructors,<br>
even the overloaded members, separated by type, and list them with their<br>
names and associated type. It even gets the types aliases and unittests,<br>
though I don&#39;t know what to do with the latter. That was part of a project<br>
to duplicate a type: generate a new type with this extracted info. I had<br>
vague projects to transform the methods into their const equivalent for<br>
example or to render the fields immutable, but didn&#39;t get that far. Would<br>
that be interesting to someone?<br>
</blockquote>
<br></div>
I could imagine extracting the unittests could be useful for making a<br>
unittest system. Are they only included when passing -unittest?<br></blockquote><div><br>Hmm, don&#39;t know. Let see:<br><br>import std.stdio;<br><br>class C<br>{<br>    int i;<br>    unittest<br>    {<br>        assert(true);<br>
        writeln(&quot;Hello World!&quot;);<br>    }<br>}<br><br>void main() {<br><br>    writeln([__traits(allMembers, C)]);<br>    writeln(typeof(C.__unittest1()).stringof);<br>    C.__unittest1();<br>}<br><br>No, compile this with and without -unittest, and __unittest1 is present. Oh, btw, contrary to the docs __traits(getOverloads, T) works also for structs and modules, not only classes.<br>
<br>The unittests type is void delegate(), which is coherent with them being blocks of instructions. You can even call it like a function (see the last line of main).<br>Strange, I never could get that to work... Maybe I didn&#39;t try this with a class.<br>
<br><br>Philippe<br> <br></div></div>