public byte[] Serialize()
{
int index = 0;
byte[] serializeBuffer = new byte[this.Size()];
serializeBuffer[index++] = this.RopId;
serializeBuffer[index++] = this.LogonId;
serializeBuffer[index++] = this.InputHandleIndex;
Array.Copy(BitConverter.GetBytes((ushort)this.PropertySizeLimit), 0, serializeBuffer, index, sizeof(ushort));
index += sizeof(ushort);
Array.Copy(BitConverter.GetBytes((ushort)this.WantUnicode), 0, serializeBuffer, index, sizeof(ushort));
index += sizeof(ushort);
Array.Copy(BitConverter.GetBytes((ushort)this.PropertyTagCount), 0, serializeBuffer, index, sizeof(ushort));
index += sizeof(ushort);
if (this.PropertyTagCount > 0)
{
IntPtr requestBuffer = new IntPtr();
requestBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(PropertyTag)));
try
{
Context.Instance.Init();
foreach (PropertyTag propTag in this.PropertyTags)
{
Marshal.StructureToPtr(propTag, requestBuffer, true);
Marshal.Copy(requestBuffer, serializeBuffer, index, Marshal.SizeOf(typeof(PropertyTag)));
index += Marshal.SizeOf(typeof(PropertyTag));
// Insert properties into Context
Context.Instance.Properties.Add(new Property((PropertyType)propTag.PropertyType));
}
}
finally
{
Marshal.FreeHGlobal(requestBuffer);
}
}
return serializeBuffer;
}