Thread overview | |||||
---|---|---|---|---|---|
|
May 23, 2014 [Issue 12791] .tupleof does not take base class fields into account | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12791 Andrej Mitrovic <andrej.mitrovich@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |INVALID --- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> --- Nevermind, just saw the docs: ----- The .tupleof property returns an $(I ExpressionTuple) of all the fields in the class, excluding the hidden fields and the fields in the base class. ----- It's a shame because it makes deep object copying more complicated than a simple one-liner. Perhaps we could use some kind of Phobos helper template to implement deep-dup-ing. -- |
June 29, 2015 [Issue 12791] .tupleof does not take base class fields into account | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12791 pabuond@gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |pabuond@gmail.com --- Comment #2 from pabuond@gmail.com --- I have been trying to find a way to dynamically retrieve all the fields of a derived class (and their value), including of course those of the base class. As you say and as described in the doc, `.tupleof` doesn't return fields from the base class (why?) Traits only help for static fields, and calling `myclassinstance.super.tupleof` doesn't work, nor does `myclassinstance.BaseClassName.tupleof` (as suggested in http://forum.dlang.org/post/mailman.69.1384804905.2552.digitalmars-d-learn@puremagic.com) Is there any way? -- |
June 30, 2015 [Issue 12791] .tupleof does not take base class fields into account | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12791 --- Comment #3 from pabuond@gmail.com --- ok, sorry, indeed __traits can do it. I know this may be out of place here but might still be useful for people landing on this page: ----------- auto b = new B; // B inherits from A foreach(i, m; __traits(allMembers, B)) static if (__traits(compiles, to!string(__traits(getMember, b, m)))) writeln(m, " = ", __traits(getMember, b, m)); ----------- prints 'name = value' for all the fields (inherited or new, static or not, etc.) of an instance of class B. -- |
Copyright © 1999-2021 by the D Language Foundation