Mono Class Library: System NamespaceSystem.SerializableAttribute Class |
See Also: SerializableAttribute Members
System.Object
System.Attribute
System.SerializableAttribute
|
This attribute indicates that the class it's being applied to is serializable. This is a requirement for all classes in an object's graph that is being serialized. A System.Runtime.Serialization.SerializationException is thrown if a class without the SerializableAttribute is serialized.[Edit]
C# Example using System; using System.IO; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Soap; public class SerializationDemo { public static void Main() { Point pt = new Point(); pt.x=1; pt.y=2; Console.WriteLine(pt); SoapFormatter formatter = new SoapFormatter(); // Serialize out to STDOUT. formatter.Serialize(System.Console.OpenStandardOutput(), pt); } } [Serializable()] public class Point { public int x,y; // Serialize This [NonSerialized()] // Don't serialize Visible attribute public bool Visible=false; public override string ToString(){ // Methods aren't serialized return String.Format("({0},{1})",x,y); } }
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0