示例#1
0
        /// <summary>
        /// Deserializes a GUID from a stream.
        /// </summary>
        /// <param name="archive">Archive containing the serialized GUID.</param>
        /// <returns>Deserialized object (type System.Guid).</returns>
        /// <exception cref="VersionNotSupportedException">Serializer version is not supported.</exception>
        public object Deserialize(SerializerArchive archive)
        {
            if (archive.Version == 1)
            {
                byte[] buffer = (byte[])archive.ReadObject();
                return(buffer.ToRfc4122Guid(0));
            }

            throw new VersionNotSupportedException(archive);
        }
示例#2
0
        /// <summary>
        /// Deserializes a generic list from a stream.
        /// </summary>
        /// <param name="archive">Archive containing a serialized generic list object.</param>
        /// <returns>Deserialized list.</returns>
        /// <exception cref="VersionNotSupportedException">Serializer version is not supported.</exception>
        public object Deserialize(SerializerArchive archive)
        {
            if (archive.Version == 1)
            {
                // read number of elements and set the capacity of the list appropriately to
                // avoid resizing while populating the list
                int count = archive.ReadInt32();

                // read elements from the archive and put them into the list
                IList collection = (IList)FastActivator.CreateInstance(archive.Type, count);
                for (int i = 0; i < count; i++)
                {
                    object obj = archive.ReadObject(archive.Context);
                    collection.Add(obj);
                }

                return(collection);
            }

            throw new VersionNotSupportedException(archive);
        }