Here is a quick tip. You all know that to serialize and deserialize an object in XML you need a default (parameter less) constructor. But sometimes you don’t want anybody to use it other than the serializer itself.
By making the default constructor obsolete you can make sure no code will directly call it.
public class MyClass
{
[Obsolete("For XML Serialization Only", true)]
public MyClass()
{
// Needed for XML serailisation
}
public MyClass(string initialValue)
{
// ...
}
// ...
}Don’t forget to specify true as the second argument to the Obsolete attribute. This will raise a compilation error if this constructor is called directly. I insist on “directly” because nothing will prevent someone to use reflection to call it. XML Serialisation can occur because it uses reflection to do it.

