Deserialize() public method

Deserialize fields in this class from a stream.
public Deserialize ( Stream stream, int size ) : int
stream Stream Stream contains a serialized instance of this class.
size int The number of bytes can read if -1, no limitation. MUST be -1.
return int
        /// <summary>
        /// Deserialize an object from a stream.
        /// </summary>
        /// <param name="stream">A stream contains object fields.</param>
        /// <param name="size">Max length can used by this deserialization
        /// if -1 no limitation except stream length.
        /// </param>
        /// <returns>The number of bytes read from the stream.</returns>
        public override int Deserialize(Stream stream, int size)
        {
            AdapterHelper.Site.Assert.AreEqual(-1, size, "The size value MUST be -1, the actual value is {0}.", size);

            int bytesRead = 0;
            int i;

            this.propertyTagCount = StreamHelper.ReadUInt32(stream);
            bytesRead            += 4;
            this.propertyTags     = new Tuple <PropertyTag, GroupPropertyName> [this.propertyTagCount];
            for (i = 0; i < this.propertyTagCount; i++)
            {
                PropertyTag tag = new PropertyTag
                {
                    PropertyType = StreamHelper.ReadUInt16(stream)
                };
                bytesRead     += 2;
                tag.PropertyId = StreamHelper.ReadUInt16(stream);
                bytesRead     += 2;
                GroupPropertyName name = null;
                if (this.IsNamedProperty(tag))
                {
                    name       = new GroupPropertyName();
                    bytesRead += name.Deserialize(stream, -1);
                }

                this.propertyTags[i] = new Tuple <PropertyTag, GroupPropertyName>(tag, name);
            }

            if (size >= 0 && bytesRead > size)
            {
                AdapterHelper.Site.Assert.Fail("The bytes length to read is larger than stream size, the stream size is {0} and the bytes to read is {1}.", size, bytesRead);
            }

            return(bytesRead);
        }