Is there a way to get the names of a function's parameters?

Simen kjaeraas simen.kjaras at gmail.com
Mon Jun 14 06:47:50 PDT 2010


Simen kjaeraas <simen.kjaras at gmail.com> wrote:

> One needs to match parentheses from the last parentheses in the  
> typeof.stringof.


string parameterNamesOf( alias fn )( ) {
     string fullName = typeof(&fn).stringof;
	
     int pos = fullName.lastIndexOf( ')' );
     int end = pos;
     int count = 0;
     do {
         if ( fullName[pos] == ')' ) {
             count++;
         } else if ( fullName[pos] == '(' ) {
             count--;
         }
         pos--;
     } while ( count > 0 );
	
     return fullName[pos+2..end];
}

-- 
Simen


More information about the Digitalmars-d mailing list