Where to put functionality of serializing a custom class?
<p>I'm starting to work with the serialization now and I think I got my class serializable after asking <a href="http://stackoverflow.com/questions/15488330/storing-and-retrieving-data-from-an-xml-file">here</a>.</p>

<p>Now I wonder if it's regarded a good, bad, depending or indifferent design to place the serialization methods <strong>inside</strong> the said class.</p>

<p>Suppose I have my class like this.</p>

<pre><code>[XmlRoot("Settings")]
public class SerializableClass
{
  public SerializableClass() { }

  [XmlElement("PropertyOne")]
  public String PropertyString { get; set; }

  [XmlElement("PropertyTwo")]
  public int PropertyInt { get; set; }

  public Object PropertyObject { get; set; }
}
</code></pre>

<p>Would it make sense to add methods like these, to let the object (de)serialize itself?</p>

<pre><code>public String SerializeMe()
{
  XmlSerializer serializer = new XmlSerializer(typeof(SerializableClass));
  StringWriter writer = new StringWriter();
  serializer.Serialize(writer, this);
  return writer.ToString();
}

public static SerializableClass DeSerialize(String input)
{
  StringReader reader = new StringReader(input);
  XmlSerializer serializer = new XmlSerializer(SerializableClass);
  return xmlSerializer.Deserialize(reader) as SerializableClass;
}
</code></pre>

<p>I would, of course, implement these with <em>try-catch</em>, <em>using</em> and some kind of file reader and only specify the path. Is it doable? Recommended? Common? (I've never used serialization implemented by me, so please bear with me if the question seems strange.)</p>
