c# - Creating Object from Class name specified in string -


i have dropdownlist on webpage has list of classnames , in c# code need instantiate object of selected items dropdownlist , call method of . classes have similar methods .

 string scalclationtype = "n0059";  var calculator = activator.createinstance("calculator", scalclationtype );   var count =  calculator.docalculation(); 

i tried casting shows "cannot convert type 'system.runtime.remoting.objecthandle' 'cypressdataimport.diabeteshelper.nqf0059" , need cast type needs same dropdown item not sure how .

//var calc = (n0059)calculator;  

how handle scenario ?

see here:

try this:

string scalclationtype = "n0059"; objecthandle handle = activator.createinstance("calculator", scalclationtype );  var calculator = (n0059)handle.unwrap(); var count = calculator.docalculation(); 

or

string scalclationtype = "n0059"; objecthandle handle = activator.createinstance("calculator", scalclationtype ); object p = handle.unwrap(); type t = p.gettype(); methodinfo method = t.getmethod("docalculation"); var count = method.invoke(p, null);  

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -