public void EmitWrite(WriterEmitContext context) { var il = context.Il; foreach (var field in fields) { var writer = AllWriters.GetWriter(field); var manifest = GetManifestValue(field); void LoadValue() { il.Emit(writer.RequiresAddress ? OpCodes.Ldflda : OpCodes.Ldfld, field); } using (context.Scope(LoadValue, manifest: manifest)) { // if the writer does not write manifest, this will write manifest for the writer if (writer is IWriteManifest == false) { context.WriteManifest(); } writer.EmitWrite(context); } if (writer is IUpdateOffset == false) { context.AddToCurrentOffset(); } } }
static ushort GetManifestValue(FieldInfo field) { var order = (byte)field.GetCustomAttribute <DataMemberAttribute>().Order; var value = AllWriters.GetWriter(field).Manifest; return((ushort)(order | (value << 8))); }
static bool IsBoundedSize(FieldInfo field) => AllWriters.GetWriter(field) is IBoundedSizeWriter;
static bool IsVarSize(FieldInfo field) => AllWriters.GetWriter(field) is IVarSizeWriter;
static IBoundedSizeWriter GetBoundedSizeWriter(FieldInfo field) => (IBoundedSizeWriter)AllWriters.GetWriter(field);
static IVarSizeWriter GetVarSizeWriter(FieldInfo field) => (IVarSizeWriter)AllWriters.GetWriter(field);