www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Get static fields!

reply DigitalDesigns <DigitalDesigns gmail.com> writes:
tupleof does not return static fields as does not Fields. 
Currently the only method seems to be use allMembers, but that 
returns members requiring filtering, which there is no good 
filtering checks. I'd simply like to get all the fields of a 
type, static and non-static.
Jun 15 2018
next sibling parent reply Bauss <jj_1337 live.dk> writes:
On Saturday, 16 June 2018 at 05:05:19 UTC, DigitalDesigns wrote:
 tupleof does not return static fields as does not Fields. 
 Currently the only method seems to be use allMembers, but that 
 returns members requiring filtering, which there is no good 
 filtering checks. I'd simply like to get all the fields of a 
 type, static and non-static.
What about derivedMembers?
Jun 16 2018
parent DigitalDesigns <DigitalDesigns gmail.com> writes:
On Saturday, 16 June 2018 at 07:56:22 UTC, Bauss wrote:
 On Saturday, 16 June 2018 at 05:05:19 UTC, DigitalDesigns wrote:
 tupleof does not return static fields as does not Fields. 
 Currently the only method seems to be use allMembers, but that 
 returns members requiring filtering, which there is no good 
 filtering checks. I'd simply like to get all the fields of a 
 type, static and non-static.
What about derivedMembers?
But I don't want derived members!
Jun 16 2018
prev sibling parent Simen =?UTF-8?B?S2rDpnLDpXM=?= <simen.kjaras gmail.com> writes:
On Saturday, 16 June 2018 at 05:05:19 UTC, DigitalDesigns wrote:
 tupleof does not return static fields as does not Fields. 
 Currently the only method seems to be use allMembers, but that 
 returns members requiring filtering, which there is no good 
 filtering checks. I'd simply like to get all the fields of a 
 type, static and non-static.
std.traits.hasStaticMember is your friend: import std.meta : Filter, staticMap, Alias, ApplyLeft; import std.traits : hasStaticMember; alias FilterMembers(T, alias Fn) = Filter!(ApplyLeft!(Fn, T), __traits(allMembers, T)); alias StaticNamesTuple(T) = FilterMembers!(T, hasStaticMember); And if you want them as aliases: alias getMember(T, string name) = Alias!(__traits(getMember, T, name)); alias GetMembers(T, names...) = staticMap!(ApplyLeft!(getMember, T), names); alias StaticMembersTuple(T) = GetMembers!(T, StaticNamesTuple!T); -- Simen
Jun 19 2018