<div class="gmail_quote">On 6 April 2012 16:53, Timon Gehr <span dir="ltr"><<a href="mailto:timon.gehr@gmx.ch">timon.gehr@gmx.ch</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I think this proposal should be merged with Johannes' one.<br></blockquote><div><br></div><div>I think Johannes proposal already nails it. What benefits would be merged from this proposal? How would they influence the design?</div>
<div> </div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 04/06/2012 11:41 AM, Johannes Pfau wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Declaring a custom attribute:<br>
---------<br>
module std.something;<br>
<br>
struct Author<br>
{<br>
    string name;<br>
    public this(string name)<br>
    {<br>
        <a href="http://this.name" target="_blank">this.name</a> = name;<br>
    }<br>
}<br>
---------<br>
<br>
Using it:<br>
---------<br>
import std.something; //Usual namespace lookup rules apply to attributes<br>
<br>
/*<br>
 * @Author(param) calls the constructor of the Author struct and<br>
 * attaches the struct instance to test. Probably @Author (without<br>
 * parenthesis) coud be made to mean std.something.Author.init<br>
 */<br>
@Author("Johannes Pfau") int test;<br>
---------<br>
<br>
Attaching attributes multiple times as in C# should be possible.<br>
<br>
Using reflection to get that attribute:<br>
---------<br>
if(__traits(hasAttribute, test, std.something.Author))<br>
{<br>
    Author[] authors = __traits(getAttribute, test,<br>
        std.something.Author);<br>
}<br>
---------<br>
<br>
An array is used here to support attaching the same attribute multiple<br>
times. Of course "auto authors = ..." should be usable here too.<br>
</blockquote>
</blockquote></div><br>