0

我正在学习 XML 序列化行为和限制。我有如下简单的 XML 文件

<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"   xmlns:cim="http://iec.ch/TC57/2001/CIM-schema-cim10#">
  <cim:BaseVoltage rdf:ID="BaseVoltage_01">
    <cim:BaseVoltage.nominalVoltage>42</cim:BaseVoltage.nominalVoltage>
  </cim:BaseVoltage>
</rdf:RDF>

c#代码:

public class Voltage
{
    public double value;
    public String units;

    public Voltage() 
    { 
    }
}

public class BaseVoltage 
{
    private Voltage volt; 

    public BaseVoltage()
    {
        volt = new Voltage();
        ConductingEquipment = new ConductingEquipment[10];
        VoltageLevel = new VoltageLevel[10];
    }

   [XmlElement("BaseVoltage.nominalVoltage")]
    public Voltage NominalVoltage
    {
        get { return volt; }
        set { volt = value; }
    }   
}

当我反序列化 xml 文件时,我的 c# 对象显示

baseVoltage.NominalVoltage.value = 0.0

我期待

baseVoltage.NominalVoltage.value = 42.

XML 序列化让我感到困惑。在这种情况下,为什么我没有得到 42 的价值?

4

0 回答 0