Skip to content

Instantly share code, notes, and snippets.

@bozhink
Created October 24, 2016 09:57
Show Gist options
  • Save bozhink/0a905dacca78ee99820b913ad7f9530a to your computer and use it in GitHub Desktop.
Save bozhink/0a905dacca78ee99820b913ad7f9530a to your computer and use it in GitHub Desktop.
Deserialize XmlDocument to object
/// <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