November 04, 2006 Any structinfo .. ? How do I get struct name at compile-time or runtime? | ||||
---|---|---|---|---|
| ||||
Is it possible to get the name of the struct automagically? It doesn't have to be at runtime, I just need it at compile time .. really. I hoped I could do the following, but it doesn't work: struct Foo { char[] getName() { return this.stuctinfo.name; //no such thing!!! } } Well .. right now I'm reading object.d and it seems there's a TypeInfo_Struct class .. but how do I get access to it? ok .... I just tried: --------------- struct x { } void main() { char[] name = (cast(TypeInfo_Struct)typeid(x)).name; writefln( name ); } ----------- but it prints out the full qualified name of the struct ... (in my case, "test.x") isn't there a straight forward way to get the struct name, like classinfo.name for classes? |
Copyright © 1999-2021 by the D Language Foundation