private void EmitWriteArrayLoop(CompilerContext ctx, Local i, Local arr) { ctx.LoadValue(0); ctx.StoreValue(i); CodeLabel label = ctx.DefineLabel(); CodeLabel label2 = ctx.DefineLabel(); ctx.Branch(label, false); ctx.MarkLabel(label2); ctx.LoadArrayValue(arr, i); if (this.SupportNull) { base.Tail.EmitWrite(ctx, null); } else { ctx.WriteNullCheckedTail(this.itemType, base.Tail, null); } ctx.LoadValue(i); ctx.LoadValue(1); ctx.Add(); ctx.StoreValue(i); ctx.MarkLabel(label); ctx.LoadValue(i); ctx.LoadLength(arr, false); ctx.BranchIfLess(label2, false); }
protected override void EmitRead(CompilerContext ctx, Local valueFrom) { Type type = ctx.MapType(typeof(List <>)).MakeGenericType(new Type[] { this.itemType }); Type expectedType = this.ExpectedType; using (Local local = this.AppendToCollection ? ctx.GetLocalWithValue(expectedType, valueFrom) : null) { using (Local local2 = new Local(ctx, expectedType)) { using (Local local3 = new Local(ctx, type)) { ctx.EmitCtor(type); ctx.StoreValue(local3); ListDecorator.EmitReadList(ctx, local3, base.Tail, type.GetMethod("Add"), this.packedWireType, false); using (Local local4 = this.AppendToCollection ? new Local(ctx, ctx.MapType(typeof(int))) : null) { Type[] types = new Type[] { ctx.MapType(typeof(Array)), ctx.MapType(typeof(int)) }; if (this.AppendToCollection) { ctx.LoadLength(local, true); ctx.CopyValue(); ctx.StoreValue(local4); ctx.LoadAddress(local3, type); ctx.LoadValue(type.GetProperty("Count")); ctx.Add(); ctx.CreateArray(this.itemType, null); ctx.StoreValue(local2); ctx.LoadValue(local4); CodeLabel label = ctx.DefineLabel(); ctx.BranchIfFalse(label, true); ctx.LoadValue(local); ctx.LoadValue(local2); ctx.LoadValue(0); ctx.EmitCall(expectedType.GetMethod("CopyTo", types)); ctx.MarkLabel(label); ctx.LoadValue(local3); ctx.LoadValue(local2); ctx.LoadValue(local4); } else { ctx.LoadAddress(local3, type); ctx.LoadValue(type.GetProperty("Count")); ctx.CreateArray(this.itemType, null); ctx.StoreValue(local2); ctx.LoadAddress(local3, type); ctx.LoadValue(local2); ctx.LoadValue(0); } types[0] = expectedType; MethodInfo method = type.GetMethod("CopyTo", types); if (method == null) { types[1] = ctx.MapType(typeof(Array)); method = type.GetMethod("CopyTo", types); } ctx.EmitCall(method); } ctx.LoadValue(local2); } } } }