Created
December 12, 2011 23:11
-
-
Save bdallen/1469582 to your computer and use it in GitHub Desktop.
This file contains 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 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