public static void Serialize(House house, string path) { var formatter = new BinaryFormatter(); using (var stream = new FileStream(path + StoragePath, FileMode.OpenOrCreate)) { formatter.Serialize(stream, house); } }
public static bool TryDeserialize(out House house, string path) { try { var formatter = new BinaryFormatter(); using (var stream = new FileStream(path + StoragePath, FileMode.OpenOrCreate)) { house = formatter.Deserialize(stream) as House; return true; } } catch (SerializationException exception) { house = null; return false; } }