Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>IsolatedStorageSettings.ApplicationSettings</code> is loading the data <strong>once</strong> - not at each access of the collection - and storing the deserialized values in memory. This makes sense, since only your application should access those application settings, they only change on the underlying storage when you save them. Therefore, they do not need to be reloaded at each access.</p> <p>Since instances of <code>Order</code> get passed around by reference (being that it is a <code>class</code>)</p> <pre><code>Order m = (Order)IsolatedStorageSettings.ApplicationSettings["myKey"] </code></pre> <p>may be (roughly) read as:</p> <ul> <li>Create a place to store a reference to an instance of the class <code>Order</code>, called <code>m</code></li> <li>Find the reference to an object corresponding to the string <code>"myKey"</code> in the current data held by the <code>ApplicationSettings</code> property of the <code>IsolatedStorage</code> class</li> <li>Indicate that the object at that location is, in fact, an instance of the <code>Order</code> class or the reference is null (throwing an exception otherwise)</li> <li>Make <code>m</code> refer to the same object in memory that the instance of the <code>Order</code> class we just found does</li> </ul> <p>This means that manipulating values on <code>m</code> will be observable via inspection of <code>(Order)IsolatedStorageSettings.ApplicationSettings["myKey"]</code> and vice versa. In short, <code>m</code> isn't just equal to the value in the application settings - it <em>is</em> the value in the application settings.</p> <p>What you should do here, to keep manipulating <code>m</code> from impacting the value read back from the settings, is to provide a mechanism to copy/clone <code>Order</code> objects and make your changes on the copy. If you're satisfied with your changes, put a <em>copy</em> of the object back in to the application settings so that further manipulation doesn't show up there (instead of the data that has actually been saved).</p> <p>There is a baked-in interface for indicating something can be copied/cloned, it is <a href="http://msdn.microsoft.com/en-us/library/system.icloneable.aspx" rel="nofollow">ICloneable</a>.</p> <p>Example:</p> <pre><code>public class Order : ICloneable { public int ID { get; set; } public object Clone() { return new Order { ID = ID }; } } </code></pre> <p>Example usage:</p> <pre><code>Order k = new Order(){ID=5}; // create order with ID of 5 IsolatedStorageSettings.ApplicationSettings.Add("mykey", k); // Save to ISO IsolatedStorageSettings.ApplicationSettings.Save(); Order m = (Order)((Order)IsolatedStorageSettings.ApplicationSettings["myKey"]).Clone(); // M = 5 m.ID = 6; // Change ID number m = (Order)((Order)IsolatedStorageSettings.ApplicationSettings["myKey"]).Clone(); // M = 5 </code></pre> <p>You could, however, write the <code>Order</code> class as follows and avoid having the second cast:</p> <pre><code>public class Order : ICloneable { public int ID { get; set; } public Order Clone() { return new Order { ID = ID }; } object ICloneable.Clone() { return Clone(); } } </code></pre> <p>Using it like so:</p> <pre><code>Order m = ((Order)IsolatedStorageSettings.ApplicationSettings["myKey"]).Clone(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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