RestSharp序列化忽略ElementName值

时间:2012-09-24 14:06:06

标签: .net xmlserializer restsharp

我正在使用RestSharp进行一些REST调用。我定义了期望XmlSerializer使用它的XmlElement ElementName参数,但它没有发生。

public class A {
    [XmlElement(ElementName = "id")]
    public int? Id { get; set; }
}

RestSharp请求位于<Id>123</Id>而不是<id>123</id>

var request = new RestRequest("/a.xml", Method.POST);
request.AddObject(A_obj); // A_obj is a instance of A
RestResponse<A> response = (RestResponse<A>)client.Execute<A>(request);

我在这里缺少什么?

1 个答案:

答案 0 :(得分:2)

RestSharp忽略XmlElement注释。请改用SerializeAs

[SerializeAs(Name = "id")]
public int? Id { get; set; }