SerializeStatus Enum
Summary
Specifies the serialization status of an object.
Members
Normal
0
Serialized
1
Deserialized
2
Syntax
public enum SerializeStatus
public enum SerializeStatus : System.Enum
Remarks
The SerializeStatus enumeration is used by the OnDeserializedAttribute and OnSerializingAttribute attributes to specify when a method should be called during the serialization or deserialization process.
The OnDeserializedAttribute attribute marks a method that is called after deserialization is complete. The OnSerializingAttribute attribute marks a method that is called before serialization begins.
Example
The following code example demonstrates how to use the SerializeStatus enumeration with the OnSerializingAttribute.
using System;
using System.Runtime.Serialization;
[Serializable]
public class MyClass
{
public string Name { get; set; }
[OnSerializing]
internal void OnSerializingMethod(StreamingContext context)
{
// This method will be called before serialization.
// The context can contain information about the serialization process.
Console.WriteLine("Serializing object...");
}
[OnDeserialized]
internal void OnDeserializedMethod(StreamingContext context)
{
// This method will be called after deserialization.
Console.WriteLine("Deserialized object.");
}
}
public class Program
{
public static void Main(string[] args)
{
MyClass obj = new MyClass { Name = "Example" };
// This would trigger the OnSerializingMethod
// var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
// using (var stream = new System.IO.MemoryStream())
// {
// formatter.Serialize(stream, obj);
// }
// This would trigger the OnDeserializedMethod
// MyClass deserializedObj = (MyClass)formatter.Deserialize(stream);
}
}