装载组件在运行时并创建类的实例 [英] Load Assembly at runtime and create class instance

查看:150
本文介绍了装载组件在运行时并创建类的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个组件。在该组件中我有一个类和接口。我需要在运行时加载本次大会,并希望创建一个类的对象,也想使用的接口。

I have a assembly. In this assembly I have a class and interface. I need to load this assembly at runtime and want to create an object of the class and also want to use the interface.

Assembly MyDALL = Assembly.Load("DALL"); // DALL is name of my dll
Type MyLoadClass = MyDALL.GetType("DALL.LoadClass"); // LoadClass is my class
object obj = Activator.CreateInstance(MyLoadClass);

这是我的code。怎么会得到改善?

This is my code. How could it be improved?

推荐答案

如果您的程序集是在GAC或者彬使用程序集名称在类型名称,而不是的Assembly.Load()<年底/ code>。

If your assembly is in GAC or bin use the assembly name at the end of type name instead of Assembly.Load().

object obj = Activator.CreateInstance(Type.GetType("DALL.LoadClass, DALL", true));

这篇关于装载组件在运行时并创建类的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆