private static void ReadAndDeserialize <T>(LockedCollection <T> collection, string filePath, ThreadSafeUI ui, bool includeComments, bool trim) where T : IStringSerializeable, new() { ReadFileLineByLine(filePath, includeComments, trim, (lineNumber, line) => { // Десериализуем объект из строки var item = new T(); if (item.DeserializeFromString(line)) { collection.AppendItem(item); } else { ui?.Log($"Skipped {typeof(T).Name} because invalid format. Line #{lineNumber}: {line}"); } }); }
private static void ReadAndDeserialize <T>(IProducerConsumerCollection <T> collection, string filePath, ThreadSafeUI ui, bool includeComments, bool trim) where T : IStringSerializeable, new() { ReadFileLineByLine(filePath, includeComments, trim, (lineNumber, line) => { // Десериализуем объект из строки var item = new T(); if (item.DeserializeFromString(line)) { if (!collection.TryAdd(item)) { throw new IOException("Unable to ReadAndAppend to ConcurrentCollection."); } } else { ui?.Log($"Пропускаю, неверная запись объекта {typeof(T).Name}. Строка #{lineNumber}: {line}"); } }); }