Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would have a shared assembly, which contains your settings class. You can then serialize/deserialize this class to a common place on the hard drive:</p> <pre><code>[XmlRoot()] public class Settings { private static Settings instance = new Settings(); private Settings() {} /// &lt;summary&gt; /// Access the Singleton instance /// &lt;/summary&gt; [XmlElement] public static Settings Instance { get { return instance; } } /// &lt;summary&gt; /// Gets or sets the height. /// &lt;/summary&gt; /// &lt;value&gt;The height.&lt;/value&gt; [XmlAttribute] public int Height { get; set; } /// &lt;summary&gt; /// Main window status (Maximized or not) /// &lt;/summary&gt; [XmlAttribute] public FormWindowState WindowState { get; set; } /// &lt;summary&gt; /// Gets or sets a value indicating whether this &lt;see cref="Settings"/&gt; is offline. /// &lt;/summary&gt; /// &lt;value&gt;&lt;c&gt;true&lt;/c&gt; if offline; otherwise, &lt;c&gt;false&lt;/c&gt;.&lt;/value&gt; [XmlAttribute] public bool IsSomething { get; set; } /// &lt;summary&gt; /// Save setting into file /// &lt;/summary&gt; public static void Serialize() { // Create the directory if (!Directory.Exists(AppTmpFolder)) { Directory.CreateDirectory(AppTmpFolder); } using (TextWriter writer = new StreamWriter(SettingsFilePath)) { XmlSerializer serializer = new XmlSerializer(typeof(Settings)); serializer.Serialize(writer, Settings.Instance); } } /// &lt;summary&gt; /// Load setting from file /// &lt;/summary&gt; public static void Deserialize() { if (!File.Exists(SettingsFilePath)) { // Can't find saved settings, using default vales SetDefaults(); return; } try { using (XmlReader reader = XmlReader.Create(SettingsFilePath)) { XmlSerializer serializer = new XmlSerializer(typeof(Settings)); if (serializer.CanDeserialize(reader)) { Settings.instance = serializer.Deserialize(reader) as Settings; } } } catch (System.Exception) { // Failed to load some data, leave the settings to default SetDefaults(); } } } </code></pre> <p>Your xml file will then look like this:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;Settings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Height="738" WindowState="Maximized" IsSomething="false" &gt; &lt;/Settings&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload