public void SaveSettings() { string path = Path.Combine(this.BasePath, "settings.xml"); XmlSerializer xmlSerializer = new XmlSerializer(typeof(MyAppSettings)); FileStream fileStream1 = new FileStream(path, FileMode.Create); FileStream fileStream2 = fileStream1; MyAppSettings appSettings = this.AppSettings; xmlSerializer.Serialize((Stream)fileStream2, (object)appSettings); fileStream1.Close(); }
public MyAppSettings LoadSettings() { string path = Path.Combine(this.BasePath, "settings.xml"); if (!File.Exists(path)) { return(new MyAppSettings()); } try { XmlSerializer xmlSerializer = new XmlSerializer(typeof(MyAppSettings)); FileStream fileStream1 = new FileStream(path, FileMode.Open); FileStream fileStream2 = fileStream1; MyAppSettings myAppSettings = xmlSerializer.Deserialize((Stream)fileStream2) as MyAppSettings; fileStream1.Close(); return(myAppSettings); } catch (Exception ex) { return(new MyAppSettings()); } }