c# - 将 .cs 变量转换为 .xml 文件
问题描述
我在 C# 中有这个程序。我想将其转换为 XML 文件,并且我想在 //Input 和 //Output 之间进行区分。例如,它应该在读取 //Input 时开始写入,并在读取 //Output 时开始写入其他内容。我知道我可以手动编写所有内容以将其转换为 XML 文件,但我需要它自动完成,这样当我稍后添加一些变量时,我不必手动将它们写入 XML 文件。
class Program
{
//Input
public static bool Power = true;
public static bool Airflow = true;
//Output
public static bool Cylinder1_Working;
public static bool Cylinder2_Working;
static void Main(string[] args)
{
if ((Power == true) && (Airflow == true))
{
Cylinder1_Working = true;
Cylinder2_Working = true;
}
}
}
我需要把上面的转换成下面的:
<LogicDefinition xsi:type="CSharpLogicDefinition" LogicName="Program">
<InputVariables>
<Variable>
<Name>Power</Name>
<Type>Bool</Type>
<Mode>Input</Mode>
</Variable>
<Variable>
<Name>Airflow</Name>
<Type>Bool</Type>
<Mode>Input</Mode>
</Variable>
</InputVariables>
<OutputVariables>
<Variable>
<Name>Cylinder1_Working</Name>
<Type>Bool</Type>
<Mode>Output</Mode>
</Variable>
<Variable>
<Name>Cylinder2_Working</Name>
<Type>Bool</Type>
<Mode>Output</Mode>
</Variable>
</OutputVariables>
<Version Major="1" Minor="1" Patch="0" />
<UserText>
if ((Power == true) && (Airflow == true)) {
Cylinder1_Working = true;
Cylinder2_Working = true;
}
</UserText>
</LogicDefinition>
我已经查看了[Serialize]
可以将其转换为 XML 的位置,但我不知道如何自行转换所有内容。我只需要一种方法来解决我的问题,因为谷歌无法帮助我解决这个问题。
解决方案
推荐阅读
- r - 如何创建以希腊符号作为列名的数据框?
- python - 需要一个项目列表,但得到了 dict djangorestframework
- javascript - Node.js 卡在 while 循环中,我不知道为什么
- c# - C# 4.0 应用程序需要访问注册表并以普通用户身份运行
- airflow - 气流使用任务实例的尝试号添加操作员链接
- shell - 在 shell 中查找和转义带有撇号的名称
- pandas - 有没有办法将标准文本文件转换为 csv 文件
- sql - 如何将一个表中的多个外键引用到 ms sql 中的单个主键
- javascript - 在Angular中对对象进行字符串化时“将循环结构转换为JSON”
- 3d - 导出所有网格