<div class="gmail_quote">On 19 March 2012 08:46, dennis luehring <span dir="ltr"><<a href="mailto:dl.soluz@gmx.net">dl.soluz@gmx.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im"><br></div>
attributes does not containing code - there just a (at-runtime) queryable information that can be attached to serveral things (like classes, methods, ...) - think of it like double.epsilon - but extendable by users - thats it, and in the c# world these attribute-definitions tend to be something like an class (but without code)<br>
<br>
in c# you can walk by (runtime)reflection through your code and find out if something is annotated with an special attribute and use the configure information and do something with it - call an constructor, open an connection, generated code (at runtime) - whatever you want<br>
<br>
its a easy-to-use-buildin-<u></u>attribution-system thats it - and people like them because c# do all the big magic by giving developers a bunch of attributes that are then used for stuff like serialization, memory-layout, ...<br>
<br>
a compiletime example of this could be:<br>
<br>
attribute my_special_attribute<br>
{<br>
int version;<br>
}<br>
<br>
attribute my_special_attribute2<br>
{<br>
string test;<br>
}<br>
<br>
class test<br>
{<br>
[my_special_attribute(version=<u></u>2)]<br>
int method1();<br>
<br>
[my_special_attribute(version=<u></u>2)]<br>
[my_special_attribute2(test="<u></u>bert")]<br>
int method2();<br>
}<br>
<br>
void main()<br>
{<br>
auto b = [ __traits(allMembers, D) ];<br>
foreach( auto a; b )<br>
{<br>
-->attribute query magic<br>
-->auto c = [ __traits(attribute("my_<u></u>special_attribute", a) ];<br>
-->auto c = [ __traits(attribute("my_<u></u>special_attribute2", a) ];<br>
<br>
//now we know all methods with my_special_attribute<br>
//and speical_special_attribute2 and their content (version=2<br>
//and test="bert"<br>
<br>
//now think of an template or mixing that uses this<br>
//information for code-generation or something like that<br>
<br>
//thats all<br>
}<br>
}<br></blockquote><div><br></div><div>+1 this post</div></div>