using ISerializable to control serialization and deserialization
[Serializable]
public class OuterClass : ISerializable
{
public OuterClass()
{
}
private OuterClass(SerializationInfo info, StreamingContext context)
{
MyField = info.GetString("MyField");
Inner = (InnerClass)info.GetValue("Inner", typeof(InnerClass));
}
#region ISerializable Members
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("MyField", MyField);
info.AddValue("Inner",Inner);
}
#endregion
public string MyField { get; set; }
public InnerClass Inner { get; set; }
}
[Serializable]
public class InnerClass : ISerializable
{
public InnerClass()
{
}
private InnerClass(SerializationInfo info, StreamingContext context)
{
MyField = info.GetString("MyField");
}
#region ISerializable Members
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("MyField", MyField);
}
#endregion
public string MyField { get; set; }
}
public class OuterClass : ISerializable
{
public OuterClass()
{
}
private OuterClass(SerializationInfo info, StreamingContext context)
{
MyField = info.GetString("MyField");
Inner = (InnerClass)info.GetValue("Inner", typeof(InnerClass));
}
#region ISerializable Members
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("MyField", MyField);
info.AddValue("Inner",Inner);
}
#endregion
public string MyField { get; set; }
public InnerClass Inner { get; set; }
}
[Serializable]
public class InnerClass : ISerializable
{
public InnerClass()
{
}
private InnerClass(SerializationInfo info, StreamingContext context)
{
MyField = info.GetString("MyField");
}
#region ISerializable Members
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("MyField", MyField);
}
#endregion
public string MyField { get; set; }
}