IDesignerSerializationManager Interface

Definition

Provides an interface that can manage design-time serialization.

public interface IDesignerSerializationManager : IServiceProvider
Derived
Implements

Examples

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;
            }
        }
    }
}

Remarks

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.

Properties

Context

Gets a stack-based, user-defined storage area that is useful for communication between serializers.

Properties

Indicates custom properties that can be serializable with available serializers.

Methods

AddSerializationProvider(IDesignerSerializationProvider)

Adds the specified serialization provider to the serialization manager.

CreateInstance(Type, ICollection, String, Boolean)

Creates an instance of the specified type and adds it to a collection of named instances.

GetInstance(String)

Gets an instance of a created object of the specified name, or null if that object does not exist.

GetName(Object)

Gets the name of the specified object, or null if the object has no name.

GetSerializer(Type, Type)

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

GetService(Type)

Gets the service object of the specified type.

(Inherited from IServiceProvider)
GetType(String)

Gets a type of the specified name.

RemoveSerializationProvider(IDesignerSerializationProvider)

Removes a custom serialization provider from the serialization manager.

ReportError(Object)

Reports an error in serialization.

SetName(Object, String)

Sets the name of the specified existing object.

Events

ResolveName

Occurs when GetName(Object) cannot locate the specified name in the serialization manager's name table.

SerializationComplete

Occurs when serialization is complete.

Applies to

Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

See also