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

About this user

manatlan http://manatlan.online.fr

« 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

   1  
   2  if hasattr(myObject,myMethod):
   3      try:
   4          retValue = getattr(myObject,myMethod)(*(),**(myArgs))
   5      except TypeError:
   6          # arguments mismatch
   7  else:
   8      # 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)

   1  
   2  String [] argNames = new String[ 1 ];
   3  String [] argValues = new String[ 1 ];
   4  
   5  argNames[0]="param";
   6  argNames[1]="value";
   7  
   8  Type t = myObject.GetType();
   9  
  10  t.InvokeMember ( myMethod, BindingFlags.InvokeMethod, null, site, argValues, null, null, argNames);
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS