自定义序列化嵌套集合对象

时间:2017-04-14 13:31:08

标签: c# restsharp xmlserializer

我正在尝试使用RestSharp的XmlSerializer序列化C#对象。

我的模特是:

        List<Address> addresses = new List<Address>();
        addresses.Add(new Address { City = "NY" });
        addresses.Add(new Address { City = "Istanbul" });

        Person person = new Person { Name = "Mike", Addresses = addresses };

        Console.WriteLine(new RestSharp.Serializers.XmlSerializer().Serialize(person));

客户端代码就像这样,没什么好看的。

<Person>
  <Name>Mike</Name>
  <Addresses>
    <Address>
      <City>NY</City>
    </Address>
    <Address>
      <City>Istanbul</City>
    </Address>
  </Addresses>
</Person>

正如所料,输出是这样的:

   <Person>
      <Name>Mike</Name>
        <Address>
          <City>NY</City>
        </Address>
        <Address>
          <City>Istanbul</City>
        </Address>
    </Person>

有没有办法获得以下结果? (删除“地址”元素名称)

https://****.hp.com/qcbin/rest/domains/DomainName/projects/ProjectName/customization/entities/requirement/types

0 个答案:

没有答案