digitalmars.D.learn - Any structinfo .. ? How do I get struct name at compile-time or runtime?
- Hasan Aljudy (28/28) Nov 03 2006 Is it possible to get the name of the struct automagically? It doesn't
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?
Nov 03 2006