August 2003
Intermediate to advanced
736 pages
14h 48m
English
To gain even more control over the serialization process, you can implement the ISerializable interface and a special constructor:
[SerializableAttribute] class MyData : ISerializable { string s = "Wahoo!"; int n = 6; public string String { get { return s; } set { value = s; n = s.Length; } } public int Length { get { return n; } } public MyData() {} #region Implementation of ISerializable public MyData( SerializationInfo info, StreamingContext context) { // Get value from name/value pairs s = info.GetString("MyString"); // Cache the string's length n = s.Length; } public void GetObjectData( SerializationInfo info, StreamingContext context) { // Add value to name/value pairs info.AddValue("MyString", s); } #endregion }
Implementing ...
Read now
Unlock full access