System.Runtime.Serialization.OnSerializingAttribute Class

When applied to a method, specifies that the method is during serialization of an object in an object graph. The order of serialization relative to other objects in the graph is non-deterministic.

See Also: OnSerializingAttribute Members


[System.AttributeUsage(System.AttributeTargets.Method, Inherited=false)]
public sealed class OnSerializingAttribute : Attribute


Use the System.Runtime.Serialization.OnSerializingAttribute to manipulate the object before serialization occurs.

To use the System.Runtime.Serialization.OnSerializingAttribute, the method must contain a System.Runtime.Serialization.StreamingContext parameter. The attribute marks the method to be called by the serialization infrastructure and the System.Runtime.Serialization.StreamingContext provides additional data about the type of serialization taking place. The usage is shown in the following code:

code reference: System.Runtime.Serialization.OnSerialization#2


In your code, you can use the word OnSerializing instead of the longer System.Runtime.Serialization.OnSerializingAttribute.


Namespace: System.Runtime.Serialization
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions:,
Since: .NET 2.0