System.Runtime.Serialization.StreamingContextStates Enumeration

Assembly: Mscorlib.dll
Namespace: System.Runtime.Serialization
Summary
Defines a set of flags that specifies the source or destination context for the stream during serialization.
C# Syntax:
[Flags]
[Serializable]
public enum StreamingContextStates
Example
The following code example demonstrates the use of the StreamingContextStates enum.
 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);
       }
    }
 }

    
See also:
System.Runtime.Serialization Namespace | FlagsAttribute

System.Runtime.Serialization.StreamingContextStates Member List:

Public Fields
All Specifies that the serialized data can be transmitted to or received from any of the other contexts.
Clone Specifies that the object graph is being cloned. Users can assume that the cloned graph will continue to exist within the same process and be safe to access handles or other references to unmanaged resources.
CrossAppDomain Specifies that the source or destination context is a different AppDomain. (For a description of AppDomains see the conceptual topic at MSDN: applicationdomains).
CrossMachine Specifies that the source or destination context is a different computer.
CrossProcess Specifies that the source or destination context is a different process on the same computer.
File Specifies that the source or destination context is a file. Users can assume that files will last longer than the process that created them and not serialize objects in such a way that deserialization will require accessing any data from the current process.
Other Specifies that the serialization context is unknown.
Persistence Specifies that the source or destination context is a persisted store, which could include databases, files, or other backing stores. Users can assume that persisted data will last longer than the process that created the data and not serialize objects so that deserialization will require accessing any data from the current process.
Remoting Specifies that the data is remoted to a context in an unknown location. Users cannot make any assumptions whether this is on the same computer.

Hierarchy:


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.