Use XDocument as the source for XmlSerializer.Deserialize?

后端 未结 5 751
-上瘾入骨i
-上瘾入骨i 2020-12-13 13:15

I would like to invoke XmlSerializer.Deserialize passing it an XDocument. It can take a Stream, an XmlReader or a T

5条回答
  •  眼角桃花
    2020-12-13 13:48

    You can use XDocument.CreateReader() to create an XmlReader that reads the contents of the XDocument.

    Equivalently, the following will work too.

    XmlReader GetReader(XDocument doc)
    {
        return doc.Root.CreateReader();
    }
    

提交回复
热议问题