Skip to content

Instantly share code, notes, and snippets.

@bdallen
Created December 12, 2011 23:11
Show Gist options
  • Save bdallen/1469582 to your computer and use it in GitHub Desktop.
Save bdallen/1469582 to your computer and use it in GitHub Desktop.
/// <summary>
/// Deserializes an XML Document to Object of T
/// </summary>
/// <typeparam name="T">Object</typeparam>
/// <param name="Buffer">XML as Byte Array</param>
/// <returns>Object of T</returns>
public static T XMLToObject<T>(Byte[] Buffer)
{
XmlSerializer formatter = new XmlSerializer(typeof(T));
MemoryStream ms = new MemoryStream(Buffer);
try
{
return (T)formatter.Deserialize(ms);
}
catch (SerializationException ex)
{
//Error.ExceptionManager.Context.LogException(ex);
return default(T);
}
finally
{
ms.Close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment