所以在过去的一个小时里,我一直在尝试使用 VB.NET 中的动态方法来调用调用类中的子类。
我有几件事没有运气。首先,在尝试遵循 MSDN (http://msdn.microsoft.com/en-us/library/ms228971.aspx) 中的示例时,我无法将该方法设为 Sub 并且根本不返回任何内容,因为我只想调用另一个方法。
例如。
Private Sub FirstMethod()
Dim methodArgs As Type() = {}
Dim MyNewMethod As New DynamicMethod("MyNewMethod", Nothing, methodArgs, GetType(Crux).Module)
Dim il As ILGenerator = MyNewMethod.GetILGenerator()
il.Emit(OpCodes.Call, OtherMethod)
il.Emit(OpCodes.Ret)
End Sub
Private Sub OtherMethod()
MsgBox("This is some other method!")
End Sub
问题是,我不希望它返回任何东西,我只希望它调用 OtherMethod() 并且我想要一种在我的代码中调用动态方法的方法(通过委托)。MSDN 根本没有真正的帮助,我找不到任何东西甚至试图解释一种方法来做我想做的事。
任何帮助是极大的赞赏。