public Serialize ( Stream stream ) : int | ||
stream | Stream | The stream where serialized instance will be wrote. |
리턴 | int |
public override int Serialize(Stream stream)
{
int bytesWritten = 0;
bytesWritten += StreamHelper.WriteGuid(stream, this.guid);
bytesWritten += StreamHelper.WriteUInt32(stream, this.kind);
if (this.kind == 0x00000000)
{
AdapterHelper.Site.Assert.IsNotNull(this.lid, "The value of GroupPropertyName.lid should not be null.");
bytesWritten += StreamHelper.WriteUInt32(stream, (uint)this.lid);
}
else if (this.kind == 0x00000001)
{
AdapterHelper.Site.Assert.IsNotNull(this.nameSize, "The value of GroupPropertyName.nameSize is null.");
bytesWritten += StreamHelper.WriteUInt32(stream, (uint)this.nameSize);
byte[] buffer = Encoding.Unicode.GetBytes(this.name, 0, this.name.Length);
bytesWritten += StreamHelper.WriteBuffer(stream, buffer);
}
return bytesWritten;
}
/// <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); }