title: Test for Optional Field when using .NET Custom Serialization
body: <p>Given a class like this one:</p>
  
  <pre><code>[Serializable]
  public class MyClass {
      string name;
      string address;
  
      public MyClass(SerializationInfo info, StreamingContext context){
          name = info.GetString("name");
          if(/* todo: check if a value for address exists */)
              address = info.GetString("address");
      }
  
      public void GetObjectData(SerializationInfo info, StreamingContext context){
          info.AddValue(name);
          if(address != null)
              info.AddValue(address);
      }
  }
  </code></pre>
  
  <p>How do I test whether a value for the <code>address</code> field exists before calling <code>info.GetString(address)</code>?</p>
  
  <p>Yes, I do understand that I could simply write a null <code>address</code> field but my real problem is that earlier versions of <code>MyClass</code>, did not have an address field.</p>
  
  <p><strong>Note:</strong> I have good reasons for using custom serialization. There are some static fields that are being used as singletons and the default deserialization will not respect that.</p>