Templates at runtime

Ary Borenszweig ary at esperanto.org.ar
Fri Feb 13 05:42:33 PST 2009


Christopher Wright wrote:
> Justin wrote:
>> Is there a way to "find" a classinfo for such a class at runtime?
> 
> The slow way:
> 
> foreach (modul; ModuleInfo)
>     foreach (info; modul.localClasses)
>         if (info.name == name) return info;
> return null;

It doesn't work. It seems only top level classes are included in the 
ModuleInfo.localClasses.

---
module main;

import std.moduleinit;
import std.stdio;

class foo {
}

class myClass(T) {
}

myClass!(int) c;

static this() {
	c = new myClass!(int)();
}

void main() {
	foreach(info; ModuleInfo.modules()) {
		if (info.name != "main") continue;
		
		writefln("%s", info.name);
		foreach(lc; info.localClasses) {
			writefln("  %s", lc.name);
		}
	}
}
---

Output:
main
   main.foo



More information about the Digitalmars-d mailing list