我希望能够解析 vb.net 代码文件,这样我就可以检查 Subs、Functions(及其内容,包括注释)、私有(private)变量等的集合。
我可以打开实际的源代码文件。
例如,如果我有:
Public Function FunctionOne(arg1 As String, arg2 as String) as Integer
here is some code
''//here are some comments
End Function
Public Sub FunctionOne(arg1 As integer, arg2 as integer)
here is some code
''//here are some comments
End Sub
我希望能够解析出所有子函数和函数以及 Public Function 和 End Function 之间的所有代码(实际上,可以选择只包含其中的代码,或者整个函数定义。
这似乎需要某种解析库,或者相当不错的正则表达式技能。
有什么建议吗?
更新: 我想要实现的主要目标是源代码的解析,所以反射也许可以很好地获取函数列表,但我知道该怎么做,但它是 的正确方法解析源代码我在想办法。
最佳答案
如何在运行时从您的程序编译它们,然后在已编译的库上使用反射?
看this microsoft thread有关如何执行此操作的详细信息!
关于c# - .Net字符串解析库,或解析.Net代码文件的regex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/615755/