views:

229

answers:

2

Is there a way to just tell the compiler, that I want my objects to be serializable by default?

+1  A: 

No, you need to decorate the objects with the Serializable attribute. FYI all objects are Xml Serializable by default. The Xml Serializer doesn't require the attribute.

I'm not sure about DataContracts but last I checked you needed to decorate them as well.

JoshBerke
+2  A: 

Pretty much every serialization engine is going to want to know that your objects are suitable. This can take the form of:

  • [Serializable]/ISerializable (BinaryFormatter,SoapFormatter)
  • [Serializable]/IXmlSerializable (and public) (XmlSerializer)
  • [DataContract]/[MessageContract] (or most of the above) (DataContractSerializer and variants)

AFAIK, there is no way of avoiding this step.

Marc Gravell