// makes list with CodeInstructions from various objects (see 'switch' for object types) public static CIList toCIList(params object[] cins) { var list = new CIList(); foreach (var i in cins) { switch (i) { case CIEnumerable ciList: list.AddRange(ciList); break; case CodeInstruction ci: list.Add(ci); break; case OpCode opcode: list.Add(new CodeInstruction(opcode)); break; case object operand: // if none of the above, it's probably operand for the last instruction Debug.assert(list.Count > 0 && list[list.Count - 1].operand == null, $"toCIList: error while trying use {i} ({i.GetType()}) as operand"); list[list.Count - 1].operand = operand; break; default: Debug.assert(false, $"toCIList: one of the params is null?"); break; } } return(list); }
// makes new list with cloned CodeInstructions public static CIList copyCIList(CIList list) { var newList = new CIList(); list.ForEach(ci => newList.Add(ci.Clone())); return(newList); }