What is serialisation and deserialisation?

Serialization is the process of converting an object instance’s state into a sequence of bits that can then be written to a stream or some other storage medium.

Deserialization is the process of converting a serialized bit stream to an instance of an object type.

The .NET Framework provides an easy-to-use serialization mechanism for object implementers. To make a class, structure, delegate, or enumeration serializable, simply attribute it with the SerializableAttribute custom attribute, as shown in the following code snippet:

[Serializable]
class SomeClass
{
public int m_public = 5000;
private int m_private = 5001;
}

Because we’ve attributed the SomeClass type with the SerializableAttribute, the common language runtime will automatically handle the serialization details for us.

Also To prevent the serialization of a field member of a type attributed with the SerializableAttribute, you can attribute the field member with the NonSerializedAttribute.

No comments:

Post a Comment