///--------------------------------------------------------------------------------
        /// <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);
        }
示例#2
0
 ///--------------------------------------------------------------------------------
 /// <summary>This method takes in an enterprise data object list of an input type
 /// and transforms it to a list of the output type.</summary>
 ///
 ///	<param name="inputEnterpriseDataObjectList">The input list to transform to this list.</param>
 ///	<param name="filterElements">Field and property values to exclude from transform.</param>
 ///
 /// <returns>An enterprise data object list of type TOutput.</returns>
 ///--------------------------------------------------------------------------------
 public static EnterpriseDataObjectList <TOutput> CreateList <TInput, TOutput>(EnterpriseDataObjectList <TInput> inputEnterpriseDataObjectList, NameObjectCollection filterElements)
     where TInput : IEnterpriseDataObject, new()
     where TOutput : IEnterpriseDataObject, new()
 {
     if (inputEnterpriseDataObjectList != null)
     {
         EnterpriseDataObjectList <TOutput> outputEnterpriseDataObjectList = new EnterpriseDataObjectList <TOutput>();
         foreach (TInput loopItem in inputEnterpriseDataObjectList)
         {
             TOutput newItem = new TOutput();
             newItem.TransformDataFromObject(loopItem, filterElements);
             outputEnterpriseDataObjectList.Add(newItem);
         }
         return(outputEnterpriseDataObjectList);
     }
     return(null);
 }
示例#3
0
 ///--------------------------------------------------------------------------------
 /// <summary>This constructor takes in an enterprise data object list of the same
 /// type and transforms it to this list.</summary>
 ///
 ///	<param name="inputEnterpriseDataObjectList">The input list to transform to this list.</param>
 ///	<param name="filterElements">Field and property values to exclude from transform.</param>
 ///	<param name="copyItems">Flag indicating whether items in the list should be copied (or retained).</param>
 ///--------------------------------------------------------------------------------
 public EnterpriseDataObjectList(EnterpriseDataObjectList <T> inputEnterpriseDataObjectList, NameObjectCollection filterElements, bool copyItems = true)
 {
     if (inputEnterpriseDataObjectList != null)
     {
         foreach (T loopItem in inputEnterpriseDataObjectList)
         {
             if (copyItems == true)
             {
                 T newItem = new T();
                 newItem.TransformDataFromObject(loopItem, filterElements);
                 Add(newItem);
             }
             else
             {
                 Add(loopItem);
             }
         }
     }
 }
        ///--------------------------------------------------------------------------------
        /// <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;
                }
            }
        }