digitalmars.D.learn - find all public properties at compile time
- gedaiu (7/7) Sep 29 2014 Hi,
- Rene Zwanenburg (8/15) Sep 30 2014 You can get the function attributes of the returned methods using
- gedaiu (9/27) Sep 30 2014 Thank you for your response!
- gedaiu (13/31) Sep 30 2014 [sorry... this is the edit for the prev post]
- anonymous (5/15) Sep 30 2014 import std.typetuple: staticMap;
- Jacob Carlborg (4/6) Sep 30 2014 It's better to use __traits(identifier) instead of .stringof.
Hi, There is a way to determine all public properties (not methods) from a struct/class at compile time? I seen that there are traits to get only methods but not properties. Am I wrong? thanks, Bogdan
Sep 29 2014
On Monday, 29 September 2014 at 20:21:43 UTC, gedaiu wrote:Hi, There is a way to determine all public properties (not methods) from a struct/class at compile time? I seen that there are traits to get only methods but not properties. Am I wrong? thanks, BogdanYou can get the function attributes of the returned methods using std.traits: http://dlang.org/library/std/traits/functionAttributes.html http://dlang.org/library/std/traits/FunctionAttribute.html Vibe's serializer is also a good place to look. The code is a bit intimidating but it's handling a ton of corner cases: https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/data/serialization.d#L710
Sep 30 2014
Thank you for your response! I don't think that it helps me... I wanted to get an array like this [ "a", "b", "c" ] for this class class test { } Bogdan On Tuesday, 30 September 2014 at 14:20:04 UTC, Rene Zwanenburg wrote:On Monday, 29 September 2014 at 20:21:43 UTC, gedaiu wrote:Hi, There is a way to determine all public properties (not methods) from a struct/class at compile time? I seen that there are traits to get only methods but not properties. Am I wrong? thanks, BogdanYou can get the function attributes of the returned methods using std.traits: http://dlang.org/library/std/traits/functionAttributes.html http://dlang.org/library/std/traits/FunctionAttribute.html Vibe's serializer is also a good place to look. The code is a bit intimidating but it's handling a ton of corner cases: https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/data/serialization.d#L710
Sep 30 2014
[sorry... this is the edit for the prev post] Thank you for your response! I don't think that it helps me... I wanted to get an array like this [ "a", "b", "c" ] for this class class test { int a; string b; double c; } Bogdan On Tuesday, 30 September 2014 at 14:20:04 UTC, Rene Zwanenburg wrote:On Monday, 29 September 2014 at 20:21:43 UTC, gedaiu wrote:Hi, There is a way to determine all public properties (not methods) from a struct/class at compile time? I seen that there are traits to get only methods but not properties. Am I wrong? thanks, BogdanYou can get the function attributes of the returned methods using std.traits: http://dlang.org/library/std/traits/functionAttributes.html http://dlang.org/library/std/traits/FunctionAttribute.html Vibe's serializer is also a good place to look. The code is a bit intimidating but it's handling a ton of corner cases: https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/data/serialization.d#L710
Sep 30 2014
On Tuesday, 30 September 2014 at 20:04:29 UTC, gedaiu wrote:[sorry... this is the edit for the prev post] Thank you for your response! I don't think that it helps me... I wanted to get an array like this [ "a", "b", "c" ] for this class class test { int a; string b; double c; }import std.typetuple: staticMap; enum stringOf(alias thing) = thing.stringof; static assert([staticMap!(stringOf, test.tupleof)] == ["a", "b", "c"]);
Sep 30 2014
On 2014-09-30 22:19, anonymous wrote:import std.typetuple: staticMap; enum stringOf(alias thing) = thing.stringof;It's better to use __traits(identifier) instead of .stringof. -- /Jacob Carlborg
Sep 30 2014