开发者

How to XmlDeserialize using RestSharp?

I'm having trouble deserializing the following XML w/ restsharp

<Xid>
   <Id>118</Id>
   <Active>true</Active>
   <Xid>20</Xid>
   <CreatedDate>2011-09-16T18:15:32</CreatedDate>
   <CreatedUserId>1782</CreatedUserId>
   <ModifiedDate>2011-09-16T18:15:32</ModifiedDate>
   <ModifiedUserId>1782</ModifiedUserId>
   <TableName>ProjectRate</TableName>
   <ObjectId>644</ObjectId>
   <Sy开发者_运维技巧stemGuid>157f2e2d-5e8b-41c7-b932-09c1d75d0ccc</SystemGuid>
</Xid>

I can't use a class named 'Xid' with a member named 'Xid' as there is a conflict in C#. I have tried manually declaring the XmlRoot on the XidClass object, but it doesn't seem to be getting picked up by RestSharp's deserializer. Is there a way to do this with RestSharp, or am I going to need to write a custome deserializer for this particular chunk of xml?


You need to create the class by hand, befoe you can deserialize the XML:

public class Xid
{
    public int Id { get; set; }
    public bool Active { get; set; }
    public int Xid { get; set; }
    ...
}

The you should be able to deserialize using something like:

Xid xid = xml.Deserialize<Xid>(response);

(Have a look here: Testing the Deserialization of RestSharp without proper REST-Api)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜