简体   繁体   中英

Instantiating a class from different .dll using reflection based on the class name?

Is there any way to instantiate a class based it name from different project/.dll without using dll = Assembly.LoadFile(@"c:\\Test.dll"); and do dll.CreateInstance(className);

I want to be able to load different class which implementing a common Interface in my application without need recompiling (something like a plugin). The dll is in the application path.

您需要以某种方式知道要从哪个程序集加载它...然后您可以使用Type.GetType(name) ,其中您传递的名称也要符合程序集名称。

I don't think there is any way to find a Dll based on only a class name or an interface a class implements, except for just finding and opening each Dll in the directory. You could use the ReflectionOnlyLoad* methods to reduce some overhead while finding the correct Dll.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM