Thread overview
How to programmatically get all the method names of an interface
Feb 25, 2022
mw
Feb 25, 2022
Ali Çehreli
Feb 26, 2022
mw
Feb 26, 2022
Ali Çehreli
February 25, 2022

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.

February 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
February 26, 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#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?)

February 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