作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
VB代码:
Public Module OnlyModule
Public Sub OnlyFunction()
'do stuff
End Sub
End Module
C#代码:
Assembly vbAssembly = BuildAssembly(vbCode); //wrapper function, but returns valid, compiled vb assembly
Module module = vbAssembly.GetModules()[0];
MethodInfo method = module.GetMethods()[0]; //returns 0 methods!!
method.Invoke(null, null);
如您所见,只有一个模块,其中只有一个函数,那么为什么我对 GetMethods() 的调用不起作用?我对 VB 不是很熟悉,但它应该是一个静态方法,而且我认为它的编写方式是正确的,它只是一个模块内的一个 sub。
最佳答案
想通了,需要使用 GetType() 而不是 GetModule():
Type type = vbAssembly.GetType("OnlyModule");
Method method = type.GetMethods()[0];
作品:)
关于c# - 使用 VBCodeProvider().CompileAssemblyFromSource 在 C# 中构建 VB 程序集但无法访问 VB 代码中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19126680/
以下 VB.NET 代码在从 Visual Studio 编译时有效: Sub Main() Dim source As Dictionary(Of String, Integer) = Ne
这是我的代码 Dim provider = New Microsoft.VisualBasic.VBCodeProvider() Dim parser = provider.CreateParser(
VB代码: Public Module OnlyModule Public Sub OnlyFunction() 'do stuff End Sub End Modul
我是一名优秀的程序员,十分优秀!