What does StreamingContextStates.Clone really do?

CLR Via C# provides an easy way to clone objects using binary serialization.

It indicates StreamingContextStates.Clone when creating a BinaryFormatter as follows:

 var formatter = new BinaryFormatter { Context = new StreamingContext(StreamingContextStates.Clone) }; 

The documentation for StreamingContextStates.Clone says that it

Indicates that cloning is an object graph. Users can assume that the cloned graph will continue to exist within the same process and be safe for accessing descriptors or other links to unmanaged resources.

Well fair - but I really don't know what that really means. How does this really change the behavior of the BinaryFormatter ? Can anyone point out any specific effects that use this flag?

+7
source share
1 answer

Serialization is here.
MS has provided an "abstract" mini structure to serialize objects.
The binary formatter is a concrete implementation of these concepts of mini-frames.

A developer can use these infrastructure concepts to create their own formatting - or -
MS when creating a mini-framework thought about the further implementation of serialization.

Therefore, they provided these flags as part of the framework.

To answer your specific question: these flags will not have any effect for binary formatting, since it is already implemented as a tool (if you want) to track the graph of an object and simply convert it to bytes of raw data.
If you create your own serializer, which in the example can save the object in the database or to a file or to shared memory or whatever, you want the user who uses your serializer to indicate the corresponding flag.

If I do not completely understand MS developers since 2003 .. :) (what is possible!)

+2
source

All Articles