コード例 #1
0
        /// <summary>
        /// Serializes the object.
        /// </summary>
        /// <param name="archive">Archive to serialize into.</param>
        /// <param name="stack">The queue to serialize.</param>
        /// <exception cref="VersionNotSupportedException">Serializer version is not supported.</exception>
        public override void Serialize(SerializationArchive archive, Stack <T> stack)
        {
            if (archive.Version == 1)
            {
                // write number of items
                int count = stack.Count;
                archive.Write(count);

                // write items (bottom up)
                var buffer = ArrayPool <T> .Shared.Rent(count);

                try
                {
                    stack.CopyTo(buffer, 0);
                    Array.Reverse(buffer, 0, count);
                    for (int i = 0; i < count; i++)
                    {
                        archive.Write(buffer[i], archive.Context);
                    }
                }
                finally
                {
                    ArrayPool <T> .Shared.Return(buffer);
                }

                return;
            }

            throw new VersionNotSupportedException(archive);
        }
コード例 #2
0
        /// <summary>
        /// Serializes the object.
        /// </summary>
        /// <param name="archive">Archive to serialize into.</param>
        /// <param name="list">The list to serialize.</param>
        /// <exception cref="VersionNotSupportedException">Serializer version is not supported.</exception>
        public override void Serialize(SerializationArchive archive, IList list)
        {
            if (archive.Version == 1)
            {
                // write number of list items
                int count = list.Count;
                archive.Write(count);

                // write list items
                for (int i = 0; i < count; i++)
                {
                    archive.Write(list[i], archive.Context);
                }

                return;
            }

            throw new VersionNotSupportedException(archive);
        }
コード例 #3
0
        /// <summary>
        /// Serializes the object.
        /// </summary>
        /// <param name="archive">Archive to serialize into.</param>
        /// <param name="set">The set to serialize.</param>
        /// <exception cref="VersionNotSupportedException">Serializer version is not supported.</exception>
        public override void Serialize(SerializationArchive archive, HashSet <T> set)
        {
            if (archive.Version == 1)
            {
                // write number of items
                int count = set.Count;
                archive.Write(count);

                // write items
                foreach (var item in set)
                {
                    archive.Write(item, archive.Context);
                }

                return;
            }

            throw new VersionNotSupportedException(archive);
        }
コード例 #4
0
        /// <summary>
        /// Serializes the object.
        /// </summary>
        /// <param name="archive">Archive to serialize into.</param>
        /// <param name="list">The list to serialize.</param>
        /// <exception cref="VersionNotSupportedException">Serializer version is not supported.</exception>
        public override void Serialize(SerializationArchive archive, SortedList <TKey, TValue> list)
        {
            if (archive.Version == 1)
            {
                // write number of list items
                int count = list.Count;
                archive.Write(count);

                // write list items
                foreach (var pair in list)
                {
                    archive.Write(pair.Key, archive.Context);
                    archive.Write(pair.Value, archive.Context);
                }

                return;
            }

            throw new VersionNotSupportedException(archive);
        }
        /// <summary>
        /// Serializes the object.
        /// </summary>
        /// <param name="archive">Archive to serialize into.</param>
        /// <param name="dictionary">The dictionary to serialize.</param>
        /// <exception cref="VersionNotSupportedException">Serializer version is not supported.</exception>
        public override void Serialize(SerializationArchive archive, SortedDictionary <TKey, TValue> dictionary)
        {
            if (archive.Version == 1)
            {
                // write number of dictionary entries
                int count = dictionary.Count;
                archive.Write(count);

                // write dictionary entries
                foreach (var pair in dictionary)
                {
                    archive.Write(pair.Key, archive.Context);
                    archive.Write(pair.Value, archive.Context);
                }

                return;
            }

            throw new VersionNotSupportedException(archive);
        }
        /// <summary>
        /// Serializes the object.
        /// </summary>
        /// <param name="archive">Archive to serialize into.</param>
        /// <param name="list">The list to serialize.</param>
        /// <exception cref="VersionNotSupportedException">Serializer version is not supported.</exception>
        public override void Serialize(SerializationArchive archive, LinkedList <T> list)
        {
            if (archive.Version == 1)
            {
                // write number of list items
                int count = list.Count;
                archive.Write(count);

                // write list items
                var node = list.First;
                while (node != null)
                {
                    archive.Write(node.Value, archive.Context);
                    node = node.Next;
                }

                return;
            }

            throw new VersionNotSupportedException(archive);
        }