/// <summary>
 /// Initializes a new instance of the <see cref="VersionNotSupportedException"/> class.
 /// </summary>
 /// <param name="archive">Serializer archive passed in during deserialization.</param>
 public VersionNotSupportedException(DeserializationArchive archive) :
     base($"Specified serializer version ({archive.Version}) is not supported for type '{archive.DataType.FullName}'.")
 {
     Type             = archive.DataType;
     RequestedVersion = archive.Version;
     MaxVersion       = Serializer.GetSerializerVersion(Type);
 }
        /// <summary>
        /// Deserializes an object.
        /// </summary>
        /// <param name="archive">Archive containing the serialized converter.</param>
        /// <returns>The deserialized collection.</returns>
        /// <exception cref="VersionNotSupportedException">Serializer version is not supported.</exception>
        public override IConverter Deserialize(DeserializationArchive archive)
        {
            if (archive.Version == 1)
            {
                lock (sConverters)
                {
                    if (!sConverters.TryGetValue(archive.DataType, out var converter))
                    {
                        converter = (IConverter)FastActivator.CreateInstance(archive.DataType);
                        sConverters.Add(archive.DataType, converter);
                    }

                    return(converter);
                }
            }

            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 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 #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 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 #5
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 #6
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 #9
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);
        }
Exemple #12
0
 /// <summary>
 /// Deserializes an object from the specified archive.
 /// </summary>
 /// <param name="archive">Archive to deserialize the object from.</param>
 /// <returns>Deserialized object.</returns>
 /// <remarks>
 /// The archive contains version information which may tell you how to deserialize it properly,
 /// if different serializer versions are available.
 /// </remarks>
 public abstract T Deserialize(DeserializationArchive archive);
Exemple #13
0
 /// <summary>
 /// Deserializes an object from the specified archive.
 /// </summary>
 /// <param name="archive">Archive to deserialize the object from.</param>
 /// <returns>Deserialized object.</returns>
 /// <remarks>
 /// The archive contains version information which may tell you how to deserialize it properly,
 /// if different serializer versions are available.
 /// </remarks>
 object IExternalObjectSerializer.Deserialize(DeserializationArchive archive)
 {
     return(Deserialize(archive));
 }