www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to programmatically get all the method names of an interface

reply mw <mingwu gmail.com> writes:
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
parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
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
parent reply mw <mingwu gmail.com> writes:
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#allMembers
Thank 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
parent =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
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