///--------------------------------------------------------------------------------
        /// <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>(ISortableDataObjectList <T> inputObject) where T : IDataObject, 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);
        }
Example #2
0
 ///--------------------------------------------------------------------------------
 /// <summary>This constructor takes in a source list from which data is copied from.
 /// Output properties can be filtered out.</summary>
 ///
 /// <param name="sourceDataObjectList">The source sortable list to copy to this list.</param>
 ///	<param name="filterElements">Field and property values to exclude from transform.</param>
 ///--------------------------------------------------------------------------------
 public SortableDataObjectList(ISortableDataObjectList <T> sourceDataObjectList, NameObjectCollection filterElements)
 {
     if (sourceDataObjectList != null)
     {
         foreach (T loopItem in sourceDataObjectList)
         {
             T newItem = new T();
             newItem.TransformDataFromObject(loopItem, filterElements);
             this.Add(newItem);
         }
     }
 }
Example #3
0
 ///--------------------------------------------------------------------------------
 /// <summary>This constructor takes in a sortable list from which data is copied from.</summary>
 ///
 /// <param name="sourceDataObjectList">The source sortable list to copy to this list.</param>
 ///--------------------------------------------------------------------------------
 public SortableDataObjectList(ISortableDataObjectList <T> sourceDataObjectList)
 {
     if (sourceDataObjectList != null)
     {
         foreach (T loopItem in sourceDataObjectList)
         {
             T newItem = new T();
             newItem.TransformDataFromObject(loopItem, null);
             this.Add(newItem);
         }
     }
 }