Exemple #1
0
        /// <summary>
        /// Deserializes an object.
        /// </summary>
        /// <param name="archive">Archive containing the serialized object.</param>
        /// <returns>The deserialized object.</returns>
        /// <exception cref="VersionNotSupportedException">Serializer version is not supported.</exception>
        public override IList Deserialize(DeserializationArchive archive)
        {
            if (archive.Version == 1)
            {
                // read number of list items
                int count = archive.ReadInt32();

                // read items from the archive and put them into the list
                var list = (IList)FastActivator.CreateInstance(archive.DataType);
                for (int i = 0; i < count; i++)
                {
                    object item = archive.ReadObject(archive.Context);
                    list.Add(item);
                }

                return(list);
            }

            throw new VersionNotSupportedException(archive);
        }
Exemple #2
0
        /// <summary>
        /// Deserializes an object.
        /// </summary>
        /// <param name="archive">Archive containing the serialized object.</param>
        /// <returns>The deserialized object.</returns>
        /// <exception cref="VersionNotSupportedException">Serializer version is not supported.</exception>
        public override HashSet <T> Deserialize(DeserializationArchive archive)
        {
            if (archive.Version == 1)
            {
                // read number of items
                int count = archive.ReadInt32();

                // read items from the archive and put them into the hash set
                var set = new HashSet <T>();
                for (int i = 0; i < count; i++)
                {
                    var item = (T)archive.ReadObject(archive.Context);
                    set.Add(item);
                }

                return(set);
            }

            throw new VersionNotSupportedException(archive);
        }
Exemple #3
0
        /// <summary>
        /// Deserializes an object.
        /// </summary>
        /// <param name="archive">Archive containing the serialized object.</param>
        /// <returns>The deserialized object.</returns>
        /// <exception cref="VersionNotSupportedException">Serializer version is not supported.</exception>
        public override Stack <T> Deserialize(DeserializationArchive archive)
        {
            if (archive.Version == 1)
            {
                // read number of items
                int count = archive.ReadInt32();

                // read items from the archive and put them onto the stack
                var stack = new Stack <T>(count);
                for (int i = 0; i < count; i++)
                {
                    var item = (T)archive.ReadObject(archive.Context);
                    stack.Push(item);
                }

                return(stack);
            }

            throw new VersionNotSupportedException(archive);
        }
Exemple #4
0
        /// <summary>
        /// Deserializes an object.
        /// </summary>
        /// <param name="archive">Archive containing the serialized object.</param>
        /// <returns>The deserialized object.</returns>
        /// <exception cref="VersionNotSupportedException">Serializer version is not supported.</exception>
        public override Queue <T> Deserialize(DeserializationArchive archive)
        {
            if (archive.Version == 1)
            {
                // read number of items
                int count = archive.ReadInt32();

                // read items from the archive and put them into the queue
                var queue = new Queue <T>(count);
                for (int i = 0; i < count; i++)
                {
                    var item = (T)archive.ReadObject(archive.Context);
                    queue.Enqueue(item);
                }

                return(queue);
            }

            throw new VersionNotSupportedException(archive);
        }
        /// <summary>
        /// Deserializes an object.
        /// </summary>
        /// <param name="archive">Archive containing the serialized collection.</param>
        /// <returns>The deserialized collection.</returns>
        /// <exception cref="VersionNotSupportedException">Serializer version is not supported.</exception>
        public override ICollection <T> Deserialize(DeserializationArchive archive)
        {
            if (archive.Version == 1)
            {
                // read number of elements
                int count = archive.ReadInt32();

                // read elements from the archive and put them into the collection
                var collection = (ICollection <T>)FastActivator.CreateInstance(archive.DataType);
                for (int i = 0; i < count; i++)
                {
                    var item = (T)archive.ReadObject(archive.Context);
                    collection.Add(item);
                }

                return(collection);
            }

            throw new VersionNotSupportedException(archive);
        }
        /// <summary>
        /// Deserializes an object.
        /// </summary>
        /// <param name="archive">Archive containing the serialized object.</param>
        /// <returns>The deserialized object.</returns>
        /// <exception cref="VersionNotSupportedException">Serializer version is not supported.</exception>
        public override LinkedList <T> Deserialize(DeserializationArchive archive)
        {
            if (archive.Version == 1)
            {
                // read number of list items
                int count = archive.ReadInt32();

                // read items from the archive and put them into the list
                var list = new LinkedList <T>();
                for (int i = 0; i < count; i++)
                {
                    var item = (T)archive.ReadObject(archive.Context);
                    list.AddLast(item);
                }

                return(list);
            }

            throw new VersionNotSupportedException(archive);
        }
Exemple #7
0
        /// <summary>
        /// Deserializes an object.
        /// </summary>
        /// <param name="archive">Archive containing the serialized object.</param>
        /// <returns>The deserialized object.</returns>
        /// <exception cref="VersionNotSupportedException">Serializer version is not supported.</exception>
        public override SortedList <TKey, TValue> Deserialize(DeserializationArchive archive)
        {
            if (archive.Version == 1)
            {
                // read number of list items
                int count = archive.ReadInt32();

                // read items from the archive and put them into the list
                var list = new SortedList <TKey, TValue>(count);
                for (int i = 0; i < count; i++)
                {
                    var key   = (TKey)archive.ReadObject(archive.Context);
                    var value = (TValue)archive.ReadObject(archive.Context);
                    list.Add(key, value);
                }

                return(list);
            }

            throw new VersionNotSupportedException(archive);
        }
        /// <summary>
        /// Deserializes an object.
        /// </summary>
        /// <param name="archive">Archive containing the serialized object.</param>
        /// <returns>The deserialized object.</returns>
        /// <exception cref="VersionNotSupportedException">Serializer version is not supported.</exception>
        public override SortedDictionary <TKey, TValue> Deserialize(DeserializationArchive archive)
        {
            if (archive.Version == 1)
            {
                // read number of dictionary entries
                int count = archive.ReadInt32();

                // read elements from the archive and put them into the dictionary
                var dictionary = new SortedDictionary <TKey, TValue>();
                for (int i = 0; i < count; i++)
                {
                    var key   = (TKey)archive.ReadObject(archive.Context);
                    var value = (TValue)archive.ReadObject(archive.Context);
                    dictionary.Add(key, value);
                }

                return(dictionary);
            }

            throw new VersionNotSupportedException(archive);
        }
        /// <summary>
        /// Deserializes an object.
        /// </summary>
        /// <param name="archive">Archive containing the serialized object.</param>
        /// <returns>The deserialized object.</returns>
        /// <exception cref="VersionNotSupportedException">Serializer version is not supported.</exception>
        public override IDictionary Deserialize(DeserializationArchive archive)
        {
            if (archive.Version == 1)
            {
                // read number of dictionary entries
                int count = archive.ReadInt32();

                // read elements from the archive and put them into the list
                var dictionary = (IDictionary)FastActivator.CreateInstance(archive.DataType);
                for (int i = 0; i < count; i++)
                {
                    object key   = archive.ReadObject(archive.Context);
                    object value = archive.ReadObject(archive.Context);
                    dictionary.Add(key, value);
                }

                return(dictionary);
            }

            throw new VersionNotSupportedException(archive);
        }