///-------------------------------------------------------------------------------- /// <summary>This method serializes an input object into a string.</summary> /// /// <param name="inputObject">The input object to serialize.</param> /// /// <returns>The string representing the serialization of the input object</returns> /// /// <returns>The serialized output.</returns> ///-------------------------------------------------------------------------------- public static string Serialize <T>(EnterpriseDataObjectList <T> inputObject) where T : IEnterpriseDataObject, new() { string serializedData = string.Empty; try { // set up output stream MemoryStream writer = new MemoryStream(); // serialize DataContractSerializer serializer = new DataContractSerializer(inputObject.GetType()); serializer.WriteObject(writer, inputObject); serializedData = System.Text.Encoding.UTF8.GetString(writer.ToArray()); writer.Close(); } catch (Exception ex) { bool reThrow = ExceptionHandler.HandleException(ex); if (reThrow) { throw; } } return(serializedData); }
///-------------------------------------------------------------------------------- /// <summary>This method deserializes a string into an object.</summary> /// /// <param name="inputString">The input string to deserialize.</param> /// <param name="inputList">The list to deserialize into.</param> /// /// <returns>The deserialized object.</returns> ///-------------------------------------------------------------------------------- public static void Deserialize <T>(string inputString, ref EnterpriseDataObjectList <T> inputList) where T : IEnterpriseDataObject, new() { try { if (inputList != null) { // set up input stream XmlReader reader = XmlReader.Create(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(inputString))); // deserialize DataContractSerializer serializer = new DataContractSerializer(inputList.GetType()); inputList = (EnterpriseDataObjectList <T>)serializer.ReadObject(reader); } } catch (Exception ex) { bool reThrow = ExceptionHandler.HandleException(ex); if (reThrow) { throw; } } }