1 module introspection.attribute; 2 3 import std.traits; 4 import introspection.type; 5 6 /// Stores information about attributes 7 struct Attribute { 8 /// 9 string name; 10 11 /// 12 Type type; 13 } 14 15 /// Returns the list of attributes associated with T 16 Attribute[] describeAttributes(alias T)() if(is(typeof(T)) && !is(typeof(T) == string)) { 17 return describeAttributeList!(__traits(getAttributes, T)); 18 } 19 20 /// Returns the list of attributes associated with T 21 Attribute[] describeAttributeList(T...)() { 22 Attribute[] list; 23 24 static foreach(attr; T) { 25 static if(isCallable!(attr)) { 26 list ~= Attribute(__traits(identifier, attr), describeType!(typeof(attr))); 27 } else static if(isType!(attr)) { 28 list ~= Attribute(attr.stringof, describeType!(attr)); 29 } else static if(__traits(compiles, attr.stringof)) { 30 list ~= Attribute(attr.stringof, describeType!(typeof(attr))); 31 } 32 } 33 34 return list; 35 }