Created
October 24, 2016 09:57
-
-
Save bozhink/0a905dacca78ee99820b913ad7f9530a to your computer and use it in GitHub Desktop.
Deserialize XmlDocument to object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Deserializes XmlDocument object to Serializable object of type T. | |
/// </summary> | |
/// <typeparam name="T">Serializable object type as output type.</typeparam> | |
/// <param name="document">XmlDocument object to be deserialized.</param> | |
/// <returns>Deserialized serializable object of type T.</returns> | |
public static T Deserialize<T>(this XmlDocument document) | |
where T : class | |
{ | |
XmlReader reader = new XmlNodeReader(document); | |
var serializer = new XmlSerializer(typeof(T)); | |
T result = (T)serializer.Deserialize(reader); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment