Indicates that a field of a serializable class should not be serialized. This class cannot be inherited.
Assembly: mscorlib (in mscorlib.dll)
This API supports the product infrastructure and is not intended to be used directly from your code. Returns a value that indicates whether this instance is equal to a specified object.(Inherited from Attribute.)
Returns the hash code for this instance.(Inherited from Attribute.)
When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.(Inherited from Attribute.)
When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.(Inherited from Attribute.)
Returns a string that represents the current object.(Inherited from Object.)
|_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)|
Maps a set of names to a corresponding set of dispatch identifiers.(Inherited from Attribute.)
|_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)|
Retrieves the type information for an object, which can be used to get the type information for an interface.(Inherited from Attribute.)
Retrieves the number of type information interfaces that an object provides (either 0 or 1).(Inherited from Attribute.)
|_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)|
Provides access to properties and methods exposed by an object.(Inherited from Attribute.)
When using the BinaryFormatter or SoapFormatter classes to serialize an object, use the attribute to prevent a field from being serialized. For example, you can use this attribute to prevent the serialization of sensitive data.
The target objects for the SerializableAttribute. During the serialization process all the public and private fields of a class are serialized by default. Fields marked with are excluded during serialization. If you are using the XmlSerializer class to serialize an object, use the XmlIgnoreAttribute class to get the same functionality. Alternatively, implement the ISerializable interface to explicitly control the serialization process. Note that classes that implement ISerializable must still be marked with SerializableAttribute.attribute are public and private fields of a serializable class. By default, classes are not serializable unless they are marked with
To apply theclass to an event, set the attribute location to field, as shown in the following C# code.
[field:NonSerializedAttribute()] public event ChangedEventHandler Changed;
If a field is not serialized, but it still requires a default value that must be supplied after deserialization, you can create a method that supplies the field with a value, then apply the OnDeserializedAttribute to the method.
For more information about using attributes, see Extending Metadata Using Attributes.
The following example demonstrates serialization of an object marked with the SerializableAttribute attribute, and the behavior of a field marked with the in the serialized object.
The code uses the SoapFormatter class to serialize the object. The class is found in the system.runtime.serialization.formatters.soap.dll, which is not loaded by default into a project. To run the code, you must add a reference to the DLL to your project.
Available since 1.1
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.