[Serializable] |
using System;
using System.Runtime.Serialization;
[Serializable()]
public class MyClass: ISerializable {
public static void Main() {}
// A handle to a window that has meaning only at this time and on this computer.
public int winhandle;
public double value = 3.14159265;
// Serialization constructor.
public MyClass (SerializationInfo info, StreamingContext context) {
// If this is a serialization to another process, winhandle must be deserialized.
if(context.State == StreamingContextStates.CrossProcess) {
winhandle = (int)info.GetValue("winhandle", typeof(int));
}
else {
// If this is a serialization from anywhere else, set winhandle to a default value.
winhandle = -1;
}
// Deserializes the value.
value = (double)info.GetValue("MyClass_value", typeof(double));
}
// Serializes the object.
public void GetObjectData(SerializationInfo info, StreamingContext context) {
// Serializes the value.
info.AddValue("MyClass_value", value);
// If this object is going not to another process but to a different computer,
// winhandle has no meaning, and does not need to be serialized.
if(context.State == StreamingContextStates.CrossProcess) {
info.AddValue("winhandle", winhandle);
}
}
}
| ctor #1 | Overloaded:.ctor(StreamingContextStates state) Initializes a new instance of the StreamingContext class with a given context state. |
| ctor #2 | Overloaded:.ctor(StreamingContextStates state, object additional) Initializes a new instance of the StreamingContext class with a given context state, and some additional information. |
| Context | Read-only Gets context specified as part of the additional context. |
| State | Read-only Gets the source or destination of the transmitted data. |
| Equals | Overridden: Determines whether two StreamingContext instances contain the same values. |
| GetHashCode | Overridden: Returns a hash code of this object. |
| GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
| ToString (inherited from System.ValueType) |
See base class member description: System.ValueType.ToString Returns the fully qualified type name of this instance. |
| Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
| MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
public StreamingContext(StreamingContext( |
state
public StreamingContext(StreamingContext( |
state
additional
public object Context {get;}
|
public StreamingContextStates State {get;}
|
obj
~StreamingContext(); |
public override int GetHashCode(); |
public Type GetType(); |
protected object MemberwiseClone(); |
public override string ToString(); |