Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

python : call an unknow method with named params

myObject is an instance of a class
myMethod is the name of the method (string)
myArgs is a dict for named arguments

if hasattr(myObject,myMethod):
    try:
        retValue = getattr(myObject,myMethod)(*(),**(myArgs))
    except TypeError:
        # arguments mismatch
else:
    # there is no "myMethod" method in myObject

call an unknow method with named params in csharp

myObject is an instance of a class
myMethod is the name of the method (string)

String [] argNames = new String[ 1 ];
String [] argValues = new String[ 1 ];

argNames[0]="param";
argNames[1]="value";

Type t = myObject.GetType();

t.InvokeMember ( myMethod, BindingFlags.InvokeMethod, null, site, argValues, null, null, argNames);
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS