List of derived types?

Michal Minich michal.minich at gmail.com
Thu Dec 16 05:43:30 PST 2010


V Thu, 16 Dec 2010 18:46:41 +0530, d coder wrote:

> Greetings
> 
> I need a way to know (using traits or other compile time constructs) all
> the types derived from a given type. Is it possible in D?
> 
> Is it possible to get a list of all the user-defined classes? I could
> use that to filter out the classes that I need.
> 
> Regards
> Cherry

you can iterate all modules to find base classes. see object_.d file to 
see sturcture of TypeInfo_Class or ModuleInfo.

     foreach(m; ModuleInfo)
        foreach (c; m.localClasses)
            if (c.base !is null)
                writefln(c.base.name);


More information about the Digitalmars-d-learn mailing list