internal void WriteStruct(StructDefinition definition, object node, bool allowRecursion = true)
{
if (node == null) throw new ArgumentNullException();
AlignWrite();
StoreObjectOffset(node);
var tag = GR2.Header.tag;
foreach (var member in definition.Members)
{
if (member.ShouldSerialize(tag))
{
var value = member.CachedField.GetValue(node);
if (member.SerializationKind == SerializationKind.UserRaw)
member.Serializer.Write(this.GR2, this, member, value);
else
WriteInstance(member, member.CachedField.FieldType, value);
}
}
// When the struct is empty, we need to write a dummy byte to make sure that another
// struct won't have the same address.
if (definition.Members.Count == 0)
{
Writer.Write((Byte)0);
}
if (Writer == MainWriter && allowRecursion)
{
// We need to write all child structs directly after the parent struct
// (at least this is how granny2.dll does it)
GR2.FlushPendingWrites();
}
}