Inheritance: SerializableBase
        /// <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);
        }
        /// <summary>
        /// Serialize current instance to a stream.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <returns>The number of bytes written to the stream.</returns>
        public override int Serialize(Stream stream)
        {
            int size = 0;

            StreamHelper.WriteUInt32(stream, this.propertyTagCount);
            size += 4;
            AdapterHelper.Site.Assert.AreEqual((int)this.propertyTagCount, this.propertyTags.Length, "This field MUST contain PropertyTagCount tags. The expected count is {0}, the actual count is {1}.", this.propertyTagCount, this.propertyTags.Length);

            for (int i = 0; i < this.propertyTagCount; i++)
            {
                PropertyTag tag = this.propertyTags[i].Item1;
                StreamHelper.WriteUInt16(stream, tag.PropertyType);
                StreamHelper.WriteUInt16(stream, tag.PropertyId);
                size += 4;
                if (this.IsNamedProperty(tag))
                {
                    GroupPropertyName name = this.propertyTags[i].Item2;
                    AdapterHelper.Site.Assert.IsNotNull(name, "The property name should not be null.");
                    size += name.Serialize(stream);
                }
            }

            return(size);
        }