title: ShouldSerialize*() vs *Specified Conditional Serialization Pattern
body: <p>I am aware of both of the ShouldSerialize* pattern and the *Specified pattern and how they work, but is there any difference between the two?  </p>
  
  <p>Are there any "gotchas" using one method vs the other when certain things should be serialized conditionally?  </p>
  
  <p>This question is specific to the usage of <code>XmlSerializer</code>, but general information regarding this topic is welcome as well.</p>
  
  <p>There is very little information on this topic out there, so it may be because they perform the exact same purpose and it's a style choice.  However, it seems strange that the .NET implementers would analyze the class via reflection and look for either/both patterns to determine how the generated serializer behaves since it slows down the generation of the serializer unless it's just a backwards compatibility artifact.</p>
  
  <p><strong>EDIT:</strong>  For those unfamiliar with the two patterns if either the <code>*Specified</code> property or <code>ShouldSerialize*</code> method returns true, then that property is serialized.</p>
  
  <pre><code>public string MyProperty { get; set; }
  
  //*Specified Pattern
  [XmlIgnore]
  public bool MyPropertySpecified { get{ return !string.IsNullOrWhiteSpace(this.MyProperty); } }
  
  //ShouldSerialize* Pattern
  public bool ShouldSerializeMyProperty()
  {
       return !string.IsNullOrWhiteSpace(this.MyProperty);
  }
  </code></pre>