private void Serialize(SettingsEntity entity) { _entity = entity; var formatter = new BinaryFormatter(); var fs = new FileStream(SettingsFileName, FileMode.Create); formatter.Serialize(fs, _entity); fs.Close(); fs.Dispose(); }
private void InitializeEntity() { var formatter = new BinaryFormatter(); if (File.Exists(SettingsFileName)) { //Десериализовать из файла var fs = new FileStream(SettingsFileName, FileMode.Open, FileAccess.Read); _entity = (SettingsEntity)formatter.Deserialize(fs); fs.Close(); fs.Dispose(); } else { _entity = InitializeEntityByDefault(); Serialize(_entity); } }
private void InitializeEntity() { var formatter = new BinaryFormatter(); if(File.Exists(SettingsFileName)) { //Десериализовать из файла var fs = new FileStream(SettingsFileName, FileMode.Open, FileAccess.Read); _entity = (SettingsEntity) formatter.Deserialize(fs); fs.Close(); fs.Dispose(); } else { _entity = InitializeEntityByDefault(); Serialize(_entity); } }
public void SaveSettings(SettingsEntity entity) { Serialize(entity); }