为什么我的序列化文件中包含单词“ArrayOf”

时间:2016-02-24 20:22:09

标签: c# xml

一个简单的课程:

public class AddressDetails
{
    public string DbServerName { get; set; }
}

所以我刚创建了两个对象的列表:

    List<AddressDetails> AdrsList = new List<AddressDetails>();

    AddressDetails detail1 = new AddressDetails();
    detail1.DbServerName = "2k8";
    AdrsList.Add(detail1);

    AddressDetails detail2 = new AddressDetails();
    detail2.DbServerName = "2k8R2D3";
    AdrsList.Add(detail2);

    Serialize(AdrsList);

想用下面的方法序列化它:

public void Serialize(List<AddressDetails> details)
{
    XmlSerializer serializer = new XmlSerializer(typeof(AddressList));
    using (TextWriter writer = new StreamWriter(@"C:\TEMP\MyXML.xml"))
    {
        serializer.Serialize(writer, details);
    }
}

它生成元素的XML中有“ArrayOf”这个词,为什么?我不想要它,它来自哪里以及如何解决它?

<?xml version="1.0" encoding="utf-8"?>
<ArrayOfAddressDetails xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <AddressDetails>
    <DbServerName>2k8</DbServerName>
  </AddressDetails>
  <AddressDetails>
    <DbServerName>2k8R2D3</DbServerName>
  </AddressDetails>
</ArrayOfAddressDetails>

0 个答案:

没有答案