c# - Retrieve type from a String -


i have class:

namespace ns1.ns2.domain {     public class process     {         private iindex indexbuilderconcr { get; set; }          public processo(string processtype) {             indexbuilderconcr = new unitycontainer().registertype<iindex, *>().resolve<iindex>();         }     } } 

here have constructor takes string. string represent type should replace * sign @ line 8. have googled araound no luck.

what you'll need type in way james s suggests, you'll need pass value method in different way calling method<resolvedprocesstype> invalid:

var type = type.gettype("some.name.space." + processtype);  var methodinfo = typeof(unitycontainer).getmethod("registertype");  // method's argument params type[] keep adding commas // each <,,,> var method = methodinfo.makegenericmethod(iindex, type);  // supply null second argument because method has no parameters unitycontainer = (unitycontainer)method.invoke(unitycontainer, null);  unitycontainer.resolve<iindex>(); 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -