Export (0) Print
Expand All

IDesignerSerializationManager Interface

Provides an interface that can manage design-time serialization.

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

public interface IDesignerSerializationManager : IServiceProvider

The IDesignerSerializationManager type exposes the following members.

  NameDescription
Public propertyContextGets a stack-based, user-defined storage area that is useful for communication between serializers.
Public propertyPropertiesIndicates custom properties that can be serializable with available serializers.
Top

  NameDescription
Public methodAddSerializationProviderAdds the specified serialization provider to the serialization manager.
Public methodCreateInstanceCreates an instance of the specified type and adds it to a collection of named instances.
Public methodGetInstanceGets an instance of a created object of the specified name, or null if that object does not exist.
Public methodGetNameGets the name of the specified object, or null if the object has no name.
Public methodGetSerializerGets a serializer of the requested type for the specified object type.
Public methodGetServiceGets the service object of the specified type. (Inherited from IServiceProvider.)
Public methodGetTypeGets a type of the specified name.
Public methodRemoveSerializationProviderRemoves a custom serialization provider from the serialization manager.
Public methodReportErrorReports an error in serialization.
Public methodSetNameSets the name of the specified existing object.
Top

  NameDescription
Public eventResolveNameOccurs when GetName cannot locate the specified name in the serialization manager's name table.
Public eventSerializationCompleteOccurs when serialization is complete.
Top

A designer can utilize IDesignerSerializationManager to access services useful to managing design-time serialization processes. For example, a class that implements the designer serialization manager can use this interface to create objects, look up types, identify objects, and customize the serialization of particular types.

The following example illustrates how to use IDesignerSerializationManager to serialize and deserialize Code DOM statements.

using System;
using System.CodeDom;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Drawing;
using System.Windows.Forms;

namespace CodeDomSerializerSample
{
    internal class MyCodeDomSerializer : CodeDomSerializer {
        public override object Deserialize(IDesignerSerializationManager manager, object codeObject) {
            // This is how we associate the component with the serializer.
                CodeDomSerializer baseClassSerializer = (CodeDomSerializer)manager.
                GetSerializer(typeof(MyComponent).BaseType, typeof(CodeDomSerializer));

            /* This is the simplest case, in which the class just calls the base class
                to do the work. */ 
            return baseClassSerializer.Deserialize(manager, codeObject);
        }

        public override object Serialize(IDesignerSerializationManager manager, object value) {
            /* Associate the component with the serializer in the same manner as with
                Deserialize */
            CodeDomSerializer baseClassSerializer = (CodeDomSerializer)manager.
                GetSerializer(typeof(MyComponent).BaseType, typeof(CodeDomSerializer));

            object codeObject = baseClassSerializer.Serialize(manager, value);

            /* Anything could be in the codeObject.  This sample operates on a
                CodeStatementCollection. */ 
            if (codeObject is CodeStatementCollection) {
                CodeStatementCollection statements = (CodeStatementCollection)codeObject;

                // The code statement collection is valid, so add a comment. 
                string commentText = "This comment was added to this object by a custom serializer.";
                CodeCommentStatement comment = new CodeCommentStatement(commentText);
                statements.Insert(0, comment);
            }
            return codeObject;
        }
    }

    [DesignerSerializer(typeof(MyCodeDomSerializer), typeof(CodeDomSerializer))]
    public class MyComponent : Component {
        private string localProperty = "Component Property Value";
        public string LocalProperty {
            get {
                return localProperty;
            }
            set {
                localProperty = value;
            }
        }
    }

}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft