ПИбд-12 Савинов Роман Дмитриевич лабораторная №6 #13

Closed
zum wants to merge 4 commits from Lab6 into Lab5
Showing only changes of commit 1c65dd299d - Show all commits

View File

@ -105,24 +105,25 @@ public class StorageCollection<T>
File.Delete(filename);
}
StringBuilder sb = new();
sb.Append(_collectionKey);
using FileStream fs = new(filename, FileMode.Create);
using StreamWriter streamWriter = new StreamWriter(fs);
streamWriter.Write(_collectionKey);
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
{
sb.Append(Environment.NewLine);
streamWriter.Write(Environment.NewLine);
// не сохраняем пустые коллекции
if (value.Value.Count == 0)
{
continue;
}
sb.Append(value.Key);
sb.Append(_separatorForKeyValue);
sb.Append(value.Value.GetCollectionType);
sb.Append(_separatorForKeyValue);
sb.Append(value.Value.MaxCount);
sb.Append(_separatorForKeyValue);
streamWriter.Write(value.Key);
streamWriter.Write(_separatorForKeyValue);
streamWriter.Write(value.Value.GetCollectionType);
streamWriter.Write(_separatorForKeyValue);
streamWriter.Write(value.Value.MaxCount);
streamWriter.Write(_separatorForKeyValue);
foreach (T? item in value.Value.GetItems())
{
@ -132,15 +133,10 @@ public class StorageCollection<T>
continue;
}
sb.Append(data);
sb.Append(_separatorItems);
streamWriter.Write(data);
streamWriter.Write(_separatorItems);
}
}
using FileStream fs = new(filename, FileMode.Create);
using StreamWriter streamWriter = new StreamWriter(fs);
streamWriter.Write(sb.ToString());
return true;
}