Implementing System.Runtime.Serialization.ISerializable : Binary Serialization « File Directory Stream « C# / CSharp Tutorial






using System;
using System.Runtime.Serialization;

[Serializable]
class EncryptableDocument :ISerializable
{
  public EncryptableDocument(){ }

  enum Field
  {
      Title,
      Data
  }
  public string Title;
  public string Data;

  public static string Encrypt(string data)
  {
      string encryptedData = data;
      return encryptedData;
  }

  public static string Decrypt(string encryptedData)
  {
      string data = encryptedData;
      return data;
  }

  public void GetObjectData(SerializationInfo info, StreamingContext context)
  {
      info.AddValue(Field.Title.ToString(), Title);
      info.AddValue(Field.Data.ToString(), Encrypt(Data));
  }

  public EncryptableDocument(SerializationInfo info, StreamingContext context)
  {
      Title = info.GetString(Field.Title.ToString());
      Data = Decrypt(info.GetString(Field.Data.ToString()));
  }
}








15.30.Binary Serialization
15.30.1.Serialize object to binary form
15.30.2.Specify NonSerialized fields
15.30.3.Serialization of an object list in binary form
15.30.4.Customized Serialization
15.30.5.Binary Custom Serialization
15.30.6.Implementing System.Runtime.Serialization.ISerializable