Provides an implementation of the System.ComponentModel.Design.Serialization.IDesignerSerializationManager interface.
See Also: DesignerSerializationManager Members
The System.ComponentModel.Design.Serialization.IDesignerSerializationManager interface is designed to be a format-independent interface to an object that controls serialization. It essentially provides context and services to serializers, which actually perform the deserialization. System.ComponentModel.Design.Serialization.IDesignerSerializationManager assists in the deserialization process by keeping track of objects. This is similar in technique to the System.ComponentModel.Design.IDesignerHost interface: designers actually provide the user interface (UI), and System.ComponentModel.Design.IDesignerHost provides the glue that allows different designers to work together.
The System.ComponentModel.Design.Serialization.DesignerSerializationManager class implements System.ComponentModel.Design.Serialization.IDesignerSerializationManager. It is designed to provide a generic form of deserialization that is similar to run-time serializers like the System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.
The System.ComponentModel.Design.Serialization.DesignerSerializationManager class achieves three goals:
It is a simple, turnkey object that can be used to deserialize a variety of formats.
It is generic and not tied to any particular format. It can be used equally for CodeDOM deserialization as well as markup deserialization.
It is extensible and supports different serialization methods that are used in copy/paste and undo/redo scenarios.
Design-time serialization has the following differences from run-time object serialization:
The object performing the serialization is generally separate from the run-time object, so that design-time logic can be removed from a component.
The serialization scheme assumes the object will be created fully initialized, and then modified through property and method invocations during deserialization.
Properties of an object that have values that were never set on the object (the properties contain the default values) are not serialized. Conversely, the deserialization stream may have holes.
Emphasis is placed on the quality of the content within the serialization stream, rather than the full serialization of an object. This means that if there is no defined way to serialize an object, that object may be skipped rather than throwing an exception. The serialization engine may provide heuristics here to decide which failures can be ignored and which are unrecoverable.
The serialization stream may have more data than is needed for deserialization. Source code serialization, for example, has user code mixed in with the code needed to deserialize an object graph. This user code must be ignored on deserialization and preserved on serialization.
Because of these differences, a different serialization model applies to design-time serialization. This model utilizes a separate serializer object for each data type being serialized. Each serializer provides its small contribution to the problem as a whole. These serializers are all coordinated through a common serialization manager. The serialization manager is responsible for maintaining state between these different serializers. As an example, consider the following class:
code reference: System.ComponentModel.Design.Serialization.DesignerSerializationManager.SampleObject#2
An instance of this class would utilize three different serializers: one for SampleObject, one for strings, and another for integers. The serializer for SampleObject is called the root serializer because SampleObject is the root of the serialization graph. More complex object graphs can be created as well. For example, consider what would happen if SampleObject were changed as follows:
code reference: System.ComponentModel.Design.Serialization.DesignerSerializationManager.SampleObject#11
This allows SampleObject to have a child that is another instance of itself. The following code fills in the object graph:
code reference: System.ComponentModel.Design.Serialization.DesignerSerializationManager.SampleObject#12
When root is serialized, there will be four serializers used: one root serializer, one serializer for the child SampleObject, one serializer for int, and one serializer for string. Serializers are cached based on type, so there is no need to create a serializer for each instance of SampleObject.
The System.ComponentModel.Design.Serialization.DesignerSerializationManager class is based on the idea of a serialization session. A session maintains state that can be accessed by the various serializers. When a session is disposed, this state is destroyed. This helps to ensure that serializers remain largely stateless, and helps to clean up serializers that are have been corrupted. The following tables describe how state is managed in and among sessions.
This state is owned by the serialization manager object, but is independent of the current serialization session.
Objects can add themselves as custom serialization providers. Because these providers are used to locate serializers, they outlive a serialization session.
This state is owned by a session and is destroyed when a session is destroyed. Consequently, accessing any properties or methods that would manipulate this state will throw an exception if the serialization manager is not in an active session.
The IDesignerSerializationManager.ResolveName event is attached by a serializer to provide additional resolution of names. All handlers are detached from this event when a session terminates.
The IDesignerSerializationManager.SerializationComplete event is raised just before a session is disposed. Then, all handlers are detached from this event.
The serialization manager maintains a table that maps between objects and their names. Serializers may give objects names for easy identification. This name table is cleared when the session terminates.
The serialization manager maintains a cache of serializers it has been asked to supply. This cache is cleared when the session terminates. The public DesignerSerializationManager.GetSerializer(Type, Type) method can safely be called at any time, but its value is cached only if it is called from within a session.
The serialization manager maintains an object called the context stack, which you can access with the IDesignerSerializationManager.Context property. Serializers can use this stack to store additional information that is available to other serializers. For example, a serializer that is serializing a property value can push the property name on the serialization stack before asking the value to serialize. This stack is cleared when the session is terminated.
The serialization manager maintains a list of errors that occurred during serialization. This list, which is accessed through the DesignerSerializationManager.Errors property, is cleared when the session is terminated. Accessing the DesignerSerializationManager.Errors property between sessions will result in an exception.