System.SerializableAttribute Class

Indicates that a class can be serialized. This class cannot be inherited.

See Also: SerializableAttribute Members

Syntax

[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Struct | System.AttributeTargets.Enum | System.AttributeTargets.Delegate | System.AttributeTargets.All, Inherited=false)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class SerializableAttribute : Attribute

Remarks

Apply the SerializableAttribute attribute to a type to indicate that instances of this type can be serialized. The common language runtime throws System.Runtime.Serialization.SerializationException if any type in the graph of objects being serialized does not have the SerializableAttribute attribute applied.

Apply the SerializableAttribute attribute even if the class also implements the System.Runtime.Serialization.ISerializable interface to control the serialization process.

When you apply the SerializableAttribute attribute to a type, all private and public fields are serialized by default. You can control serialization more granularly by implementing the System.Runtime.Serialization.ISerializable interface to override the serialization process.

Or you can exclude fields from serialization by applying the NonSerializedAttribute attribute to the field. If a field of a serializable type contains a pointer, a handle, or some other data structure that is specific to a particular environment, and cannot be meaningfully reconstituted in a different environment, then you might want to apply the NonSerializedAttribute attribute to that field.

For more information about using attributes, see [<topic://cpconExtendingMetadataUsingAttributes>]. For more information about serialization, see System.Runtime.Serialization.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0