【发布时间】:2023-04-01 11:50:01
【问题描述】:
我有一个 Xml 配置文件,其中包含 true 和 false 语句。我需要一个function,它将返回bool 值。
<Configs>
<steerWithMouse>true</steerWithMouse>
<debug>false</debug>
</Configs>
该函数需要一个string 值才能让节点执行。所以是这样的:
bool steerWithMouse = ReadConfigs("SteerWithMouse");
bool debug = ReadConfigs("debug");
public bool ReadConfigs(string config) {
try {
//Where the code should go.
}
catch {
//If the program fails to find or load the file correctly.
ModConsole.Error("Falied to load configs file."); //The console.
steerWithMouse = true;
debug = false;
}
}
由于我在 Xml 文件方面缺乏经验,我在尝试执行此操作时只会遇到挫折。它要么什么也没说,要么没有编译,要么返回了整个文档。我很乐意接受一些帮助。
【问题讨论】:
-
您对如何读取 xml 文件并解析其数据做了哪些研究?你有没有发现什么有用的东西?您是否应用了它并尝试解决此问题?
-
是的,我整天(昨天)一直在寻找一堆解决方案。但这些都没有帮助我。我删除了它,因为我的代码在注释掉 sn-ps 和半行的地方有多乱。
-
您是否考虑过让AppSettings 处理读取部分,而让TryParse 处理字符串值?
-
您能分享您尝试过的任何解决方案并告诉我们您遇到的问题吗?