static void AddPacketsToDocument(IDocumentObject doc, LogPacket[] packets) { PacketLogDocument packetLog = doc as PacketLogDocument; TestDocument testDoc = doc as TestDocument; if (packetLog != null) { foreach (LogPacket packet in packets) { packetLog.AddPacket((LogPacket)packet.Clone()); } } else if (testDoc != null) { IEnumerable <LogPacket> newPackets = packets.Select(p => (LogPacket)p.Clone()); testDoc.AddRangeInputPacket(newPackets); } }