将.cs变量转换为.xml文件

时间:2019-02-25 06:31:40

标签: c# xml variables

我已经用C#编写了这个程序。我想将其转换为XML文件,并且要在// Input和// Output之间进行区别。例如,它应该在读//输入时开始写,并在读//输出时开始写其他东西。我知道我可以手动编写所有内容以将其转换为XML文件,但是我需要将其自动完成,因此以后添加一些变量时,不必手动将其写入XML文件。 / p>

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) &amp;&amp; (Airflow == true)) {
       Cylinder1_Working = true;
       Cylinder2_Working = true;
     }
  </UserText>
</LogicDefinition>

我看过[Serialize],可以将其转换为XML,但是我不知道如何单独使用。我只需要一种解决问题的方法,因为Google对此无能为力。

0 个答案:

没有答案