System.Design
2.0.0.0
System.Object
System.ComponentModel.Design.Serialization.IDesignerSerializationManager
The 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. assists in the deserialization process by keeping track of objects. This is similar in technique to the interface: designers actually provide the user interface (UI), and provides the glue that allows different designers to work together.
The class implements . It is designed to provide a generic form of deserialization that is similar to run-time serializers like the .
The 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 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.
Global State
This state is owned by the serialization manager object, but is independent of the current serialization session.
-
Object
Usage
-
Serialization providers
Objects can add themselves as custom serialization providers. Because these providers are used to locate serializers, they outlive a serialization session.
Session-Owned State
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.
-
Object
Usage
-
event
The event is attached by a serializer to provide additional resolution of names. All handlers are detached from this event when a session terminates.
-
event
The event is raised just before a session is disposed. Then, all handlers are detached from this event.
-
Name table
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.
-
Serializer cache
The serialization manager maintains a cache of serializers it has been asked to supply. This cache is cleared when the session terminates. The public method can safely be called at any time, but its value is cached only if it is called from within a session.
-
Context stack
The serialization manager maintains an object called the context stack, which you can access with the 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.
-
Error list
The serialization manager maintains a list of errors that occurred during serialization. This list, which is accessed through the property, is cleared when the session is terminated. Accessing the property between sessions will result in an exception.
Provides an implementation of the interface.
Constructor
2.0.0.0
This constructor sets the and properties to true.
Initializes a new instance of the class.
Constructor
2.0.0.0
If a serializer requests services that cannot be satisfied by the serialization manager, the default implementation will forward those requests to the parameter.
This constructor sets the and properties to true.
Initializes a new instance of the class with the given service provider.
An .
Property
2.0.0.0
System.ComponentModel.IContainer
To be added.
If a container exists, all components that are created by the serialization manager will be added to the container. The default implementation of this property will search the service provider for an and use the container provided by the designer host, should one exist. Otherwise, this property will return null and no components will be added to a container.
Gets or sets to the container for this serialization manager.
Method
2.0.0.0
System.Object
This method is called by serializers when they attempt to create an instance of a type. The default implementation creates a new instance of the type, or it may return an existing instance depending on the values of the and properties. The method uses reflection to create instances and will perform some generic transformations on parameters to find a matching constructor.
Creates an instance of a type.
A new instance of the type specified by .
The type to create an instance of.
The parameters of the type’s constructor. This can be null or an empty collection to invoke the default constructor.
A name to give the object. If null, the object will not be given a name, unless the object is added to a container and the container gives the object a name.
true to add the object to the container if the object implements ; otherwise, false.
Method
2.0.0.0
System.IDisposable
Most data within the serialization manager is transient and only lives for the life of a serialization session. When a session is disposed, serialization is considered to be complete and this transient state is cleared. This allows a single instance of a serialization manager to be used to serialize multiple object trees. Some state, including the service provider and any custom serialization providers that were added to the serialization manager, span sessions.
Creates a new serialization session.
An that represents a new serialization session.
Property
2.0.0.0
System.Collections.IList
To be added.
You can only read the error list while a serialization session is active.
Gets the list of errors that occurred during serialization or deserialization.
Method
2.0.0.0
System.Object
To be added.
You can request the type of serializer you would like. This method returns null if there is no serializer of the requested type for the specified object type.
Gets the serializer for the given object type.
The serializer for , or null, if not found.
The type of serializer to retrieve.
Method
2.0.0.0
System.Object
To be added.
The method provides access to the underlying container or service provider that was set in the constructor.
Gets the requested service.
The requested service, or null if the service cannot be resolved.
Method
2.0.0.0
System.Type
To be added.
The method will search the service provider for an and, if available, it will delegate to that service to resolve the type. If an is not available, will call the method.
Gets the requested type.
The requested type, or null if the type cannot be resolved.
Method
2.0.0.0
System.Void
Raising an event invokes the event handler through a delegate. For more information, see Raising an Event.
The method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.
Raises the event.
A that contains the event data.
Method
2.0.0.0
System.Void
Raising an event invokes the event handler through a delegate. For more information, see Raising an Event.
The method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.
Raises the event.
An that contains the event data.
Method
2.0.0.0
System.Void
Raising an event invokes the event handler through a delegate. For more information, see Raising an Event.
The method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.
Raises the event.
An that contains the event data.
Property
2.0.0.0
System.Boolean
To be added.
The property determines the behavior of the method. If true, will pass the given component name. If false, will check for the presence of the given name in the container. If the name does not exist in the container, will use the given name. If the name does exist in the container, will pass a null value as the name of a component when adding it to the container, thereby giving it a new name. This second variation is useful for implementing a serializer that always duplicates objects, rather than assuming those objects do not exist. Paste commands often use this type of serializer.
You can only change this property when you are not in a serialization session.
Gets or sets a value indicating whether the method should check for the presence of the given name in the container.
Property
2.0.0.0
System.Object
To be added.
The property provides a way to give the serialization manager a set of serialization properties that serializers can use to guide their behavior.
This object's public properties will be inspected and wrapped in new property descriptors that have a target object of the serialization manager.
Gets the object that should be used to provide properties to the serialization manager's property.
Property
2.0.0.0
System.Boolean
To be added.
If the property is false, the method will always create a new instance of a type. If is true, will first search the name table and container for an object of the same name. If such an object exists and is of the same type, will return the existing instance. This second variation is useful for implementing a serializer that applies serialization state to an existing set of objects, rather than always creating a new tree. The Undo command often uses this type of serializer.
In the case where the property is true, the property will further modify the behavior of depending on the types of the two objects.
Gets or sets a flag indicating whether will always create a new instance of a type.
Event
2.0.0.0
System.EventHandler
To be added.
Occurs when a session is created.
Event
2.0.0.0
System.EventHandler
To be added.
Occurs when a session is disposed.
Method
2.0.0.0
System.Void
When the method is used to request a serialization provider, the serialization manager queries the custom serialization providers first before looking in the type's metadata for the appropriate serializer.
Adds a custom serialization provider to the serialization manager.
The serialization provider to add.
Property
2.0.0.0
System.ComponentModel.Design.Serialization.ContextStack
To be added.
A context stack provides a user-defined storage area, implemented as a stack. This storage area is a useful way to provide communication across serializers, as serialization is a generally hierarchical process.
Gets the context stack for this serialization session.
Method
2.0.0.0
System.Object
To be added.
Implements the method.
The newly created object instance.
The data type to create.
The arguments to pass to the constructor for this type.
The name of the object. This name can be used to access the object later through . If null is passed, the object is still created but cannot be accessed by name.
true to add this object to the design container. The object must implement for this to have any effect.
Method
2.0.0.0
System.Object
To be added.
Retrieves an instance of a created object of the specified name.
An instance of the object with the given name, or null if no object by that name can be found.
The name of the object to retrieve.
Method
2.0.0.0
System.String
To be added.
If the method cannot find a corresponding name for the parameter, it raises the event before it returns null.
Retrieves a name for the specified object.
The name of the object, or null if the object is unnamed.
Method
2.0.0.0
System.Object
To be added.
To be added.
Gets a serializer of the requested type for the specified object type.
An instance of the requested serializer, or null if no appropriate serializer can be located.
The type of the serializer to retrieve.
Method
2.0.0.0
System.Type
To be added.
To be added.
Gets a type of the specified name.
An instance of the type, or null if the type cannot be loaded.
Property
2.0.0.0
System.ComponentModel.PropertyDescriptorCollection
To be added.
To be added.
Implements the property.
Method
2.0.0.0
System.Void
The method removes a custom serialization provider that was previously added by a call to the method.
Removes a previously added serialization provider.
The to remove.
Method
2.0.0.0
System.Void
To be added.
Serializers can be written to handle recoverable errors gracefully by calling the method with the error information. The serialization manager may support reporting a list of errors after it completes, or it may throw an exception from this method and abort the serialization process. The serializer should continue after calling this function.
adds the parameter to the collection. If is null, no action is taken.
Used to report a recoverable error in serialization.
Method
2.0.0.0
System.Void
The method provides a way to set the name of an existing object. This enables creation of an instance of the object through a call to the method, avoiding the overhead of the method.
Sets the name for the specified object.
The object to set the name.
A used as the name of the object.
Method
2.0.0.0
System.Object
To be added.
This member is an explicit interface member implementation. It can be used only when the instance is cast to an interface.
For a description of this member, see the method.
A service object of type .
-or-
null if there is no service object of type .
Property
2.0.0.0
System.Boolean
To be added.
The property modifies the behavior of the method when the property is true, as detailed in the following table.
-
RecycleInstances
ValidateRecycledTypes
Behavior of CreateInstance
-
false
true or false
Always create a new instance of the specified type
-
true
false
If a matching instance is found it is returned, regardless of its type.
-
true
true
If a matching instance is found, it is returned only if its type is the same as specified in the method call.
is useful for morphing one type of object to another if they have similar properties but share no common parent or interface.
Gets or sets a flag indicating whether the method will verify that matching names refer to the same type.