title: Serializing only some properties?
body: <p>I'm working in Windows Phone 7, but I suppose the question may be Silverlight in general (not .NET though, as <code>ISerializable</code> doesn't exist in Windows Phone as <a href="https://stackoverflow.com/questions/2451008/how-to-seralize-only-some-properties-in-net">suggested in this answer</a>).</p>
  
  <p>I have an number of objects I create at run time. They will mostly always be the same, except for a few properties.</p>
  
  <p>So I would have as an object:</p>
  
  <pre><code>Public Class Article
      Public Property Title As String
      Public Property Author As String
      Public Property HasBeenViewed As Boolean
      Public Property DateViewed As Date
      Public Property IsPriorityArticle As Boolean
  End Class
  </code></pre>
  
  <p>I'd like to be able to write this as:</p>
  
  <pre><code>&lt;DataContract()&gt;
  Public Class Article
      &lt;IgnoreDataMember()&gt; _
      Public Property Title As String
      &lt;IgnoreDataMember()&gt; _
      Public Property Author As String
      &lt;DataMember()&gt; _
      Public Property HasBeenViewed As Boolean
      &lt;DataMember()&gt; _
      Public Property DateViewed As Date
      &lt;DataMember()&gt; _
      Public Property IsPriorityArticle As Boolean
  End Class
  </code></pre>
  
  <p>I have a lot of article objects to load at startup. Note: Articles that are loaded at startup are the <em>only</em> articles - there are never any new articles or any articles deleted. The only things that are changed in the <code>Article</code> object is <code>IsPriorityArticle</code>,  <code>HasBeenViewed</code> and <code>DateViewed</code>. The rest of it is static. </p>
  
  <p>I load these articles into a <code>List(Of Article)</code> and that becomes my data source for binding. As the user views the articles, it logs when it was last viewed and that date. <code>IsPriorityArticle</code> may have a true or false value that can be changed by the user - the end user can mark if it is considered an important article (in which case it will show up in another page of priority articles) or to unmark it as false. If so, that new value needs to persist between sessions.</p>
  
  <p>I have about 250 articles. I create these all on start up (again, there will never be more or less articles).</p>
  
  <p>Initialized values sample:</p>
  
  <pre><code>Public Shared Property MyArticles As IEnumerable(Of Article)
  
  Private Sub Application_Launching(ByVal sender As Object, ByVal e As LaunchingEventArgs)
      Dim listOfArticles As New List(Of Article)
      With listOfArticles
          .Add(New Article With {.Title = "The Internet", .Author = "John", _
                                 .IsPriorityArticle = False})
          .Add(New Article With {.Title = "The World", .Author = "Jim", _
                                 .IsPriorityArticle = False})
          .Add(New Article With {.Title = "The Universe", .Author = "John", _
                                 .IsPriorityArticle = True})
          .Add(New Article With {.Title = "The Atom", .Author = "Jim", _
                                 .IsPriorityArticle = True})
      End With
      MyArticles = listOfArticles
  End Sub
  </code></pre>
  
  <p>(BTW, I know I don't need the line continuation character anymore, but this site won't format code without it)</p>
  
  <p>Notice the last 2 - they have <code>.IsPriorityArticle = True</code>. That is the initialized value when the app is first launched - if the user never changes it, it will always be <code>.IsPriorityArticle = True</code> but if they change it to <code>False</code>, that should persist in IsolatedStorage to the next session.</p>
  
  <p>So I've toyed around with trying to get this to serialize properly and can't get anything to work. I don't know how to load only the <code>&lt;DataMember&gt;</code> properties from IsoStore and not the rest.</p>
  
  <p>Does anyone know how to do this so that my <code>MyArticles As IEnumerable(Of Article)</code> will use my initialized values and then check for any <code>&lt;DataMember&gt;</code> properties that need to be updated?</p>
  
  <p>Or am I down the wrong path on this?</p>