1 module dattrs;
2 
3 template dattrs_this_body(string[] names, ARGS...)
4 {
5     static string dattrs_this_body()
6     {
7         string this_body;
8         static foreach(int i, t; ARGS)
9         {
10             this_body = "this."~names[i]~" = "~names[i]~";";
11         }
12         return this_body;
13     }
14 }
15 
16 template this_args(string[]names, ARGS...)
17 {
18     static string this_args()
19     {
20         string this_args;
21         static foreach(int i, t; ARGS)
22         {
23             this_args ~= t.stringof~" "~names[i]~",";
24         }
25         return this_args;
26     }
27 }
28 
29 
30 mixin template dattrs(string[] names, ARGS...)
31 {
32     mixin("this("~this_args!(names, ARGS)~"){"~dattrs_this_body!(names, ARGS)~"}");
33 
34     static foreach(int i, t; ARGS)
35     {
36         mixin(t," "~names[i]~";");
37     }
38 }
39 
40 
41 unittest
42 {
43     assert (w.donkey == property_value);
44 }