c# - 验证配置文件 C# 的内容
问题描述
我需要验证现有配置文件的内容。
它看起来像这样:
<configuration>
<appSettings>
<Version>HB.2017.0</Version>
<FORMAT_VERSION>2.4</FORMAT_VERSION>
<MISC>Stuff.2014.0</MISC>
</appSettings>
</configuration>
我一直在尝试用 C# 编写一些东西来读取文件并分配 and 的内容,Version
然后Format-Version
验证它是否为真,但我不断收到空指针错误。
这是我到目前为止所拥有的:
public void ValidateConfigVersionSetting()
{
XmlDocument doc = new XmlDocument();
doc.Load(@"C:\project.exe.config");
XmlNode node = doc.DocumentElement.SelectSingleNode("/Version");
string nodeContent = node.InnerText;
if (nodeContent.Equals("2017.0"))
{
Report.Success("Config", "Config is correct! 2017.");
}
else
{
Report.Failure("Config", "Config is not 2017.");
}
}
这是 Ranorex 自动化套件的代码模块,因此Validate.IsTrue
来自它。我存储的方式是否innertext
正确?
解决方案
如果该代码与编写的完全相同,那么您在这里有一个错误:
Validate.IsTrue(nodeContent="HB.2017.0", "Config is proper");
您将字符串分配给 nodeContent,而不是比较它。
推荐阅读
- laravel - 如何更改 Laravel 集合输出中的某些值
- pandas - 我正在尝试将 DataFrame 中的某些列从浮点数转换为整数
- vue.js - Vue Capacitor Ionic 4 Uncaught TypeError:无法重新定义属性:队列
- php - 提交时表单未发送电子邮件。我错过了什么?
- python-3.x - ValueError:传递了与“cell.state_size”不兼容的“initial_state”
- android - 如果我使用图书馆,我必须对用户说
- java - JSON 响应已使用 Jackson 和 JAX-RS 异常映射器转义引号
- powershell - 是否可以在 Powershell 中自定义详细消息前缀?
- tensorflow - 在同一台机器上安装 Nvidia CUDA ver10 会破坏 CUDA ver9 吗?
- r - 使用一组断点将数据分位数