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
2008-12-04 14:04:37
+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
(andpublic
) (XmlSerializer
)[DataContract]
/[MessageContract]
(or most of the above) (DataContractSerializer
and variants)
AFAIK, there is no way of avoiding this step.
Marc Gravell
2008-12-04 21:38:55