public void EmitSizeEstimator(WriterEmitContext context) { if (Type.IsValueType) { writer.EmitSizeEstimator(context); } else { var il = context.Il; var nullLbl = il.DefineLabel(); var end = il.DefineLabel(); context.LoadValue(); il.Emit(OpCodes.Brfalse, nullLbl); writer.EmitSizeEstimator(context); il.LoadIntValue(2); il.Emit(OpCodes.Add); il.Emit(OpCodes.Br_S, end); il.MarkLabel(nullLbl); il.LoadIntValue(2); il.MarkLabel(end); } }
public override void EmitSizeEstimator(WriterEmitContext context) { using (context.GetLocal <int>(out var sum)) { LoopOver(context, (ctx, loadValue) => { using (context.Scope(loadValue)) { itemWriter.EmitSizeEstimator(ctx); } // stack: size ctx.Il.Load(sum); ctx.Il.Emit(OpCodes.Add); ctx.Il.Store(sum); // add and store in the sum }); var il = context.Il; il.Load(sum); // add 2 for the count il.LoadIntValue(2); il.Emit(OpCodes.Add); } }