How to programmatically get all the method names of an interface

Ali Çehreli acehreli at yahoo.com
Sat Feb 26 05:31:05 UTC 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



More information about the Digitalmars-d-learn mailing list