开发者

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.Lo开发者_JAVA百科adFile(@"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.


You'll need to know which assembly to load it from somehow... then you can use Type.GetType(name) where the name you pass is qualified with the assembly name as well.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜