c# - how to pass a string value to a type of expression? -
public void invoke(string methodname) { string funcname=methodname.split('.')[1]; //funcname contains value of customercontroller type type = typeof(funcname); methodinfo method = type.getmethod(funcname); customercontroller c = new customercontroller(); string result = (string)method.invoke(c, null); } in need pass string value typeof expression class name. i’m getting compile time error. in above code
type type = typeof(funcname); here funcname contains value "customercontroller". if replace below line works fine.
type type = typeof(customercontroller); how can pass string value typeof expression?
you can use type.gettype
type.gettype(classname); you have give full class name. if class defined in assembly need specify name of assembly name.
type.gettype("name.space.classname"); type.gettype("name.space.classname, otherassemblyname"); if nested class can specify name +
type.gettype("name.space.classname+nestedclassname, otherassemblyname");
Comments
Post a Comment