Example #1
0
        /// <summary>
        /// Deserializes a string representation of an object back into an
        /// actual object
        /// </summary>
        /// <param name="serializedObject">string representation of the object</param>
        /// <returns>deserialized object</returns>
        public static object DeserializeObject(string serializedObject, LegacyDeserializers.LegacyDeserializationHelper helper)
        {
            // parameter checking
            if(serializedObject == null)
                throw new ArgumentNullException("serializedObject", "DeserializeObject: string cannot be null.");

            object obj = null;
            byte[] bytes = Convert.FromBase64String(serializedObject);

            if (bytes != null && bytes.Length > 0)
            {
                MemoryStream stream = new MemoryStream(bytes);
                using (stream)
                {
                    BinaryFormatter formatter = new BinaryFormatter();

                    if (helper != null)
                    {
                        if (helper.Binder != null) formatter.Binder = helper.Binder;
                        if (helper.Surrogate != null) formatter.SurrogateSelector = helper.Surrogate;
                    }

                    obj = formatter.Deserialize(stream);
                    stream.Close();
                    formatter = null;
                }
                stream = null;
            }
            bytes = null;
            return obj;
        }
Example #2
0
 public SettingSaver(string fileName, LegacyDeserializers.LegacyDeserializationHelper helper)
 {
     this.path = GetPath(fileName);
     this.helper = helper;
 }