Thread overview
get only user-defined members
Dec 16, 2017
Marc
Dec 16, 2017
Jonathan M Davis
Dec 16, 2017
Marc
Dec 16, 2017
Jonathan M Davis
December 16, 2017
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" ... ]?
December 16, 2017
On Saturday, December 16, 2017 04:01:10 Marc via Digitalmars-d-learn wrote:
> 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" ... ]?

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 Davis

December 16, 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:
>> 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" ... ]?
>
> 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 Davis

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.
December 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:
> > On Saturday, December 16, 2017 04:01:10 Marc via
> >
> > Digitalmars-d-learn wrote:
> >> 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" ... ]?
> >
> > 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 Davis
>
> 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.

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 Davis