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

Gary Willoughby dev at nomad.so
Sun Sep 8 09:43:15 PDT 2013


On Sunday, 8 September 2013 at 13:46:26 UTC, Dicebot wrote:
> 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);
> }

This looks like a nice solution but i get errors when used across 
modules. The problem is that allmembers emits private members so 
across modules they are not available.


More information about the Digitalmars-d-learn mailing list