Using traits get a list of methods and filter out the member vars.

Dicebot public at dicebot.lv
Sun Sep 8 06:46:24 PDT 2013


http://dpaste.dzfl.pl/c250e798

import std.traits, std.range;

private template Methods(T)
	if (is(T == class))
{
	private string[] getMethods()
	{
		string result[];
		
		foreach (member_string; __traits(allMembers, T))
		{
			mixin("alias member = " ~ T.stringof ~ "." ~ member_string ~ 
";");
			static if (is(typeof(member) == function))
			{

				result ~= __traits(identifier, member);
			}
		}	
		return result;
	}
	
	enum Methods = getMethods().join("\n");
}

class A
{
	int a;
	void delegate() dg;
	void foo() { }
}

void main()
{
	pragma(msg, Methods!A);
}


More information about the Digitalmars-d-learn mailing list