C# Convert dynamic object to interface -
namespace mynamespace { public interface imyinterface { string getmethod(); } public class myclass : imyinterface { public string getmethod() {} } }
//main program
var ruleclass = activator.createinstance(assembly.getexecutingassembly().fullname, "mynamespace.myclass"); if( ruleclass != null) { imyinterface myclass = (imyinterface)ruleclass; //throws exception. }
how can convert ruleclass
imyinterface
type can call specific methods in it?
use unwrap
method.
imyinterface myclass = (imyinterface)ruleclass.unwrap();
you can create directly too
var myclass = activator.createinstance(typeof(myclass)) myclass;
Comments
Post a Comment