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

Popular posts from this blog

amazon web services - S3 and apache mod_proxy with basic authentication -

How to install ruby on rails -

powershell - This solution contains one or more assemblies targeted for the global assembly cache -