如何检查VB.NET中是否会引发事件?我似乎能够在C#中完成它,但在VB中却没有,即使我使用相同的语法.
这是我的VB.NET语法(返回错误)
If [EVENT] IsNot Nothing Then
End If
Run Code Online (Sandbox Code Playgroud)
这是我的C#语法(完美运行)
If([EVENT] != null) //If an event is not null(nothing)
{
}
Run Code Online (Sandbox Code Playgroud)
这是VB代码返回的错误
"[EVENT]是一个事件,不能直接调用.使用'RaiseEvent'语句来引发事件."
这篇文章与Visual Basic .NET 2010有关
所以,我想知道是否有任何方法可以从库中调用函数,例如System.ReadAllBytes通过字符串名称.
我一直在努力Assembly.GetExecutingAssembly().CreateInstance和System.Activator.CreateInstance追随CallByName(),但它们似乎都没有奏效.
我如何尝试它的示例:
Dim Inst As Object = Activator.CreateInstance("System.IO", False, New Object() {})
Dim Obj As Byte() = DirectCast(CallByName(Inst, "ReadAllBytes", CallType.Method, new object() {"C:\file.exe"}), Byte())
Run Code Online (Sandbox Code Playgroud)
帮助(一如既往)非常感谢