get literal symbol name without base class/struct as string

Dr.No jckj33 at gmail.com
Tue Apr 17 21:45:45 UTC 2018


give structs like this:

struct A
{
	int a = 10;
	string s = "haha";
}

struct B
{
	A aDetails;
}

I'd like to do this and store that symbol name as string (my goal 
is store the member name);

string memberName = magic(B.aDetails.s);
writeln(memberName); // otuput "aDetails.s"

how can I do that?

closet I got was:

template nameof(alias S) {
	import std.array : split, join;
	import std.traits;
	pragma(msg, fullyQualifiedName!S);
	pragma(msg, "stringof = " ~ S.stringof);
	enum parts = fullyQualifiedName!S.split(".");
	enum nameof = parts[1 .. $].join(".");
}


but neither fullyQualifiedName nor stringof give the symbol in 
the way I need.


More information about the Digitalmars-d-learn mailing list