public IEnumerator <PacketSaveDataNG> GetEnumerator() { try { List <PacketSaveDataNG> blockCol = new List <PacketSaveDataNG>(); pReader = new PcapReader(_fileName); string linkLayer = ((int)pReader.Header.LinkType).ToString(); pReader.OnReadPacketEvent += delegate(object context, IPacket packet) { PacketSaveDataNG psdng = new PacketSaveDataNG(HexStreamType.Raw, packet.Data.ToHex()); psdng.Details[PacketSaveDataNGProtoFields.ENCAPS_TYPE] = linkLayer; blockCol.Add(psdng); }; pReader.ReadPackets(CancellationToken.None); foreach (var packet in blockCol) { yield return(packet); } } finally { pReader?.Dispose(); } }