private void LoadSettings() { if (_loginOptions == null) { if (File.Exists("LogInOptions.xml")) { using (var stream = File.OpenRead("LogInOptions.xml")) { var serializer = new XmlSerializer(typeof(SavedLogInOptions)); _loginOptions = serializer.Deserialize(stream) as SavedLogInOptions; } UserName = _loginOptions.UserName; Password = _loginOptions.Password; RememberPassword = _loginOptions.RememberPassword; IpAddress = _loginOptions.IpAddress; PortNumber = _loginOptions.PortNumber; if (!RememberPassword) { Password = null; } } else { UserName = null; Password = null; RememberPassword = false; IpAddress = "127.0.0.1"; PortNumber = 8500; } } }
private void SaveSettings() { SavedLogInOptions loginOptions = new SavedLogInOptions() { UserName = userName, Password = password, RememberPassword = rememberPassword, IpAddress = ipAddress, PortNumber = portNumber }; using (var stream = File.Open("LogInOptions.xml", FileMode.Create)) { var serializer = new XmlSerializer(typeof(SavedLogInOptions)); serializer.Serialize(stream, loginOptions); } }