DesignerSerializationManager Class

 

Provides an implementation of the IDesignerSerializationManager interface.

Namespace:   System.ComponentModel.Design.Serialization
Assembly:  System.Design (in System.Design.dll)

System.Object
  System.ComponentModel.Design.Serialization.DesignerSerializationManager

public class DesignerSerializationManager : IDesignerSerializationManager, 
	IServiceProvider

NameDescription
System_CAPS_pubmethodDesignerSerializationManager()

Initializes a new instance of the DesignerSerializationManager class.

System_CAPS_pubmethodDesignerSerializationManager(IServiceProvider)

Initializes a new instance of the DesignerSerializationManager class with the given service provider.

NameDescription
System_CAPS_pubpropertyContainer

Gets or sets to the container for this serialization manager.

System_CAPS_pubpropertyErrors

Gets the list of errors that occurred during serialization or deserialization.

System_CAPS_pubpropertyPreserveNames

Gets or sets a value indicating whether the CreateInstance method should check for the presence of the given name in the container.

System_CAPS_pubpropertyPropertyProvider

Gets the object that should be used to provide properties to the serialization manager's Properties property.

System_CAPS_pubpropertyRecycleInstances

Gets or sets a flag indicating whether CreateInstance will always create a new instance of a type.

System_CAPS_pubpropertyValidateRecycledTypes

Gets or sets a flag indicating whether the CreateInstance method will verify that matching names refer to the same type.

NameDescription
System_CAPS_protmethodCreateInstance(Type, ICollection, String, Boolean)

Creates an instance of a type.

System_CAPS_pubmethodCreateSession()

Creates a new serialization session.

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetRuntimeType(String)

Gets the type corresponding to the specified type name.

System_CAPS_pubmethodGetSerializer(Type, Type)

Gets the serializer for the given object type.

System_CAPS_protmethodGetService(Type)

Gets the requested service.

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodGetType(String)

Gets the requested type.

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_protmethodOnResolveName(ResolveNameEventArgs)

Raises the ResolveName event.

System_CAPS_protmethodOnSessionCreated(EventArgs)

Raises the SessionCreated event.

System_CAPS_protmethodOnSessionDisposed(EventArgs)

Raises the SessionDisposed event.

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_pubeventSessionCreated

Occurs when a session is created.

System_CAPS_pubeventSessionDisposed

Occurs when a session is disposed.

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_priveventIDesignerSerializationManager.ResolveName

Occurs when IDesignerSerializationManager.GetName cannot locate the specified name in the serialization manager's name table.

System_CAPS_pubinterfaceSystem_CAPS_priveventIDesignerSerializationManager.SerializationComplete

Occurs when serialization is complete.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIDesignerSerializationManager.AddSerializationProvider(IDesignerSerializationProvider)

Adds a custom serialization provider to the serialization manager.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIDesignerSerializationManager.CreateInstance(Type, ICollection, String, Boolean)

Implements the CreateInstance method.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIDesignerSerializationManager.GetInstance(String)

Retrieves an instance of a created object of the specified name.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIDesignerSerializationManager.GetName(Object)

Retrieves a name for the specified object.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIDesignerSerializationManager.GetSerializer(Type, Type)

Gets a serializer of the requested type for the specified object type.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIDesignerSerializationManager.GetType(String)

Gets a type of the specified name.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIDesignerSerializationManager.RemoveSerializationProvider(IDesignerSerializationProvider)

Removes a previously added serialization provider.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIDesignerSerializationManager.ReportError(Object)

Used to report a recoverable error in serialization.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIDesignerSerializationManager.SetName(Object, String)

Sets the name for the specified object.

System_CAPS_pubinterfaceSystem_CAPS_privmethodIServiceProvider.GetService(Type)

For a description of this member, see the GetService method.

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIDesignerSerializationManager.Context

Gets the context stack for this serialization session.

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIDesignerSerializationManager.Properties

Implements the Properties property.

The 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. IDesignerSerializationManager assists in the deserialization process by keeping track of objects. This is similar in technique to the IDesignerHost interface: designers actually provide the user interface (UI), and IDesignerHost provides the glue that allows different designers to work together.

The DesignerSerializationManager class implements IDesignerSerializationManager. It is designed to provide a generic form of deserialization that is similar to run-time serializers like the BinaryFormatter.

The 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:

public class SampleObject
{
    private string stringValue = null;
    private int intValue = int.MinValue;

    public string StringProperty 
    { 
        get { return this.stringValue; }

        set { this.stringValue = value; }
    }

    public int IntProperty 
    {
        get { return this.intValue; }

        set{ this.intValue = value; }
    }
}

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:

public class SampleObject
{
    private string stringValue = null;
    private int intValue = int.MinValue;
    private SampleObject childValue = null;

    public string StringProperty
    {
        get { return this.stringValue; }

        set { this.stringValue = value; }
    }

    public int IntProperty
    {
        get { return this.intValue; }

        set { this.intValue = value; }
    }

    public SampleObject Child
    {
        get { return this.childValue; }

        set { this.childValue = value; }
    }
}

This allows SampleObject to have a child that is another instance of itself. The following code fills in the object graph:

class Program
{
    static void Main(string[] args)
    {
        SampleObject root = new SampleObject();

        SampleObject currentObject = root;

        for (int i = 0; i < 10; i++)
        {
            SampleObject o = new SampleObject();

            currentObject.Child = o;

            currentObject = o;
        }
    }
}

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 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.

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.

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

ResolveName event

The ResolveName event is attached by a serializer to provide additional resolution of names. All handlers are detached from this event when a session terminates.

SerializationComplete event

The SerializationComplete 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 GetSerializer 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 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.

Error list

The serialization manager maintains a list of errors that occurred during serialization. This list, which is accessed through the Errors property, is cleared when the session is terminated. Accessing the Errors property between sessions will result in an exception.

.NET Framework
Available since 2.0

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: