reflection - C# MethodInfo Invoke -


i can't find problem in code. i'm trying find particular kind of property , invoke method on it.

the function following:

private string getlangtranslator(object root) {      var properties = root.gettype().getproperties();       foreach (var property in properties)      {          if (typeof(multilanguage) == property.propertytype)          {                                     methodinfo m = property.propertytype.getmethod("translate");                  return m.invoke(property.propertytype, new object[] {value1}) string;                              }      }       return null; } 

and exception following:

system.reflection.targetexception: 'object not match target type.' 

you should:

object propvalue = property.getvalue(root); return m.invoke(propvalue, new object[] {value1}) string; 

the first parameter of invoke instance of object want call method/property... need retrieve value of property first.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -