digitalmars.D.learn - How to programmatically get all the method names of an interface
- mw (3/3) Feb 25 2022 How to programmatically get all the method names of an interface;
- =?UTF-8?Q?Ali_=c3=87ehreli?= (8/11) Feb 25 2022 Perhaps allMembers?
- mw (11/14) Feb 25 2022 Thank you, Ali.
- =?UTF-8?Q?Ali_=c3=87ehreli?= (25/28) Feb 25 2022 I will let others to correct me but getOverloads is what I would start
How to programmatically get all the method names of an interface; actually I want a flattened view, i.e also includes all the methods from its (many) ancestors, the whole inheritance lattice.
Feb 25 2022
On 2/25/22 14:05, mw wrote:How to programmatically get all the method names of an interface; actually I want a flattened view, i.e also includes all the methods from its (many) ancestors, the whole inheritance lattice.Perhaps allMembers? https://dlang.org/spec/traits.html#allMembers The following are the two that help with most such needs: - __traits (the page above) - The std.traits module: https://dlang.org/phobos/std_traits.html Ali
Feb 25 2022
On Friday, 25 February 2022 at 23:28:21 UTC, Ali Çehreli wrote:On 2/25/22 14:05, mw wrote: Perhaps allMembers? https://dlang.org/spec/traits.html#allMembersThank you, Ali. It kind of works, but "No name is repeated", in the example on that page: ``` void foo() { } int foo(int) { return 0; } ``` only one "foo" is returned, how do I get the signature info of these two different methods? (I'm trying to do some introspection of D code, is this possible?)
Feb 25 2022
On 2/25/22 16:00, mw wrote:only one "foo" is returned, how do I get the signature info of these two different methods? (I'm trying to do some introspection of D code, is this possible?)I will let others to correct me but getOverloads is what I would start to struggle with myself: import std.stdio; class B { void bar() {} } class D : B { this() { } ~this() { } void foo() { } int foo(int) { return 0; } } void main() { foreach (member; __traits(allMembers, D)) { foreach (overload; __traits(getOverloads, D, member)) { writefln!"%s: %s"(member, typeof(overload).stringof); } } } There are many other traits that may help untangle everything but I am not sure. Ali
Feb 25 2022