public static void LoadFromFile() { try { string jRes; using (StreamReader streamReader = new StreamReader(SettingsFile, Encoding.UTF8)) { jRes = streamReader.ReadToEnd(); //MessageBox.Show(jRes); } SettingsObject settingsObject = JsonSerializer.Deserialize <SettingsObject>(jRes); City = settingsObject.City; foreach (var i in settingsObject.strWidgets) { if (i == "weather") { widgets.Add(new WeatherWidget(form, new Point(0, Settings.widgets.Count * 100))); } else if (i == "currency") { widgets.Add(new CurrencyWidget(form, new Point(0, Settings.widgets.Count * 100))); } else if (i == "clock") { widgets.Add(new ClockTypeOne(form, new Point(0, Settings.widgets.Count * 100))); } } } catch { } }
public static void WritoToFile() { SettingsObject settingsObject = new SettingsObject(City, WriteWidgets()); string jRes = JsonSerializer.Serialize(settingsObject); //MessageBox.Show(jRes); StreamWriter streamWriter = new StreamWriter(SettingsFile, false, Encoding.UTF8); streamWriter.Write(jRes); streamWriter.Flush(); streamWriter.Close(); }