0
sample.vb
class sam
public shared sub hh()
Console.WriteLine("asasas")
end sub
end class

test.vb
Dim ass as Assembly  = Assembly.LoadFile("sample.dll")

现在,我想使用类名调用共享方法。我该怎么做?

4

1 回答 1

1

反射是你的朋友。添加一个Imports System.Reflection并尝试以下操作:

Sub Main()
    Dim ass As Assembly = Assembly.LoadFile("sample.dll")
    Dim t_sam As Type = ass.GetType("sam")
    Dim hh_m As MethodInfo = t_sam.GetMethod("hh", BindingFlags.Public Or BindingFlags.Static)
    hh_m.Invoke(Nothing, New Object() {})
End Sub
于 2012-05-08T06:06:05.983 回答