Imports System.Reflection
Imports System.Activator
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim dllPath As String = "DLL名称"
’导入DLL
Dim a As Assembly = Assembly.LoadFrom(dllPath)
Dim key As String = "命名空间" + "." + "类名"
'获取类的类型
Dim b As Type = a.GetType(key)
‘根据获取的类生成这个类的一个实例
Dim c As Object = Activator.CreateInstance(b)
Dim methodname As String = "方法名"
’根据获取的类,得到指定方法的信息
Dim d As MethodInfo = b.GetMethod(methodname)
'调用方法执行
d.Invoke(c, New Object() {"参数1", "参数2"})
End Sub
End Class
利用反射机制可以实现根据读取的外部配置文件(配置文件中要记录以下信息:调用的DLL名称,DLL中类的命名空间,类名,方法名ÿ