Tutorial by Examples

Add the [Serializable] attribute to mark an entire object for binary serialization: [Serializable] public class Vector { public int X; public int Y; public int Z; [NonSerialized] public decimal DontSerializeThis; [OptionalField] public string Name; } All...
If you use the [NonSerialized] attribute, then that member will always have its default value after deserialization (ex. 0 for an int, null for string, false for a bool, etc.), regardless of any initialization done in the object itself (constructors, declarations, etc.). To compensate, the attribut...
That would get more control over serialization, how to save and load types Implement ISerializable interface and create an empty constructor to compile [Serializable] public class Item : ISerializable { private string _name; public string Name { get { return _name; } ...
Implements a serialization surrogate selector that allows one object to perform serialization and deserialization of another As well allows to properly serialize or deserialize a class that is not itself serializable Implement ISerializationSurrogate interface public class ItemSurrogate : ISerial...
The binder gives you an opportunity to inspect what types are being loaded in your application domain Create a class inherited from SerializationBinder class MyBinder : SerializationBinder { public override Type BindToType(string assemblyName, string typeName) { if (typeName.Eq...
This small example shows how you can lose backward compatibility in your programs if you do not take care in advance about this. And ways to get more control of serialization process At first, we will write an example of the first version of the program: Version 1 [Serializable] class Data { ...

Page 1 of 1