digitalmars.D.learn - get only user-defined members
- Marc (4/9) Dec 15 2017 then return only ["name", "age"] rather ["name, "age", "ctor",
- Jonathan M Davis (8/19) Dec 15 2017 Try __traits(derivedMembers, Person).
- Marc (8/30) Dec 16 2017 It derivedMembers worked but I didn't understand how so. It
- Jonathan M Davis (7/42) Dec 16 2017 Every class in D other than Object is derived from another class. So, I
how do I from class:class Person { string name; int age; }do:auto c = [__traits(allMembers, Person)];then return only ["name", "age"] rather ["name, "age", "ctor", "toString" ... ]?
Dec 15 2017
On Saturday, December 16, 2017 04:01:10 Marc via Digitalmars-d-learn wrote:how do I from class:Try __traits(derivedMembers, Person). https://dlang.org/spec/traits.html#derivedMembers Depending on what you want though, it's not all that uncommon to use a variety of traits to filter the list down to whatever it is that you actually want. std.traits and std.meta are your friends in addition to __traits. - Jonathan M Davisclass Person { string name; int age; }do:auto c = [__traits(allMembers, Person)];then return only ["name", "age"] rather ["name, "age", "ctor", "toString" ... ]?
Dec 15 2017
On Saturday, 16 December 2017 at 07:23:38 UTC, Jonathan M Davis wrote:On Saturday, December 16, 2017 04:01:10 Marc via Digitalmars-d-learn wrote:It derivedMembers worked but I didn't understand how so. It returned the proper array ["name", "age", "this"] but how are them derived? or it's D's design that every class is implicitily derived from a "main objet"? Thanks for your suggeston on std.traits and std.meta, I didn't know about the last one.how do I from class:Try __traits(derivedMembers, Person). https://dlang.org/spec/traits.html#derivedMembers Depending on what you want though, it's not all that uncommon to use a variety of traits to filter the list down to whatever it is that you actually want. std.traits and std.meta are your friends in addition to __traits. - Jonathan M Davisclass Person { string name; int age; }do:auto c = [__traits(allMembers, Person)];then return only ["name", "age"] rather ["name, "age", "ctor", "toString" ... ]?
Dec 16 2017
On Saturday, December 16, 2017 15:28:46 Marc via Digitalmars-d-learn wrote:On Saturday, 16 December 2017 at 07:23:38 UTC, Jonathan M Davis wrote:Every class in D other than Object is derived from another class. So, I assume that the derived in derivedMembers was chosen to indicate that it didn't include any members from base classes. So, it's not that the members are derived from anything; it's that the members come from the derived class. - Jonathan M DavisOn Saturday, December 16, 2017 04:01:10 Marc via Digitalmars-d-learn wrote:It derivedMembers worked but I didn't understand how so. It returned the proper array ["name", "age", "this"] but how are them derived? or it's D's design that every class is implicitily derived from a "main objet"? Thanks for your suggeston on std.traits and std.meta, I didn't know about the last one.how do I from class:Try __traits(derivedMembers, Person). https://dlang.org/spec/traits.html#derivedMembers Depending on what you want though, it's not all that uncommon to use a variety of traits to filter the list down to whatever it is that you actually want. std.traits and std.meta are your friends in addition to __traits. - Jonathan M Davisclass Person { string name; int age; }do:auto c = [__traits(allMembers, Person)];then return only ["name", "age"] rather ["name, "age", "ctor", "toString" ... ]?
Dec 16 2017