Roman
Roman

Reputation: 10403

How do serializables work in .net?

What happens when I annotate a class with serializable? Can I serialize them into json or XML? How is this done?

Upvotes: 0

Views: 77

Answers (2)

Oded
Oded

Reputation: 499142

The SerializableAttribute is just a marker attribute that does nothing.

When using it, you are claiming that every component of your class can be serialized - in order to actually serialize the class you need to use a serializer such as the XmlSerializer or DataContractSerializer.

To use the DataContractSerializer, you need to decorate your classes and class members with different attributes (DateMemberAttribute, for example). It give you better control over the output XML than the XmlSerializer does and can also output JSON.

Upvotes: 2

Ward Bekker
Ward Bekker

Reputation: 6366

This allows the class to be serialized with the available serializers, like xmlserializer and the binary serializer. However, more annotations are probably required to output it in the desired xml layout (or JSON)

Documentation

Upvotes: 0

Related Questions