我需要解析一些C#
文件来获取一些常量变量的值。我知道我可以做这样的事情
$input = Get-Content C:somefile.cs ...
然后遍历每一行并进行一些文本匹配。
。但想知道我是否可以利用某种 C#
DOM 对象来获取常量的值?
可以从 powershell 命令行动态加载类型,然后计算常量。
例:
C:\somefile.cs 内容:
public static class Foo
{
public const string SOME_CONSTANT = "StackOverflow";
}
Powershell命令行:
Add-Type -Path C:somefile.cs
$constantValue = [Foo]::SOME_CONSTANT