Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
IDesignerSerializationManager Interface

IDesignerSerializationManager Interface

Provides an interface that can manage design-time serialization.

For a list of all members of this type, see IDesignerSerializationManager Members.

System.IServiceProvider
   System.ComponentModel.Design.Serialization.IDesignerSerializationManager

[Visual Basic]
Public Interface IDesignerSerializationManager
   Inherits IServiceProvider
[C#]
public interface IDesignerSerializationManager : IServiceProvider
[C++]
public __gc __interface IDesignerSerializationManager : public
   IServiceProvider
[JScript]
public interface IDesignerSerializationManager implements
   IServiceProvider

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.

Example

[Visual Basic, C#, C++] The following example illustrates how to use IDesignerSerializationManager to serialize and deserialize Code DOM statements.

[Visual Basic] 
Imports System
Imports System.CodeDom
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.ComponentModel.Design.Serialization
Imports System.Drawing
Imports System.Windows.Forms

Namespace CodeDomSerializerSample
   Friend Class MyCodeDomSerializer
      Inherits CodeDomSerializer

      Public Overrides Function Deserialize(ByVal manager As IDesignerSerializationManager, _
                                                ByVal codeObject As Object) As Object
         ' This is how we associate the component with the serializer.
         Dim baseClassSerializer As CodeDomSerializer = CType(manager.GetSerializer( _
                GetType(MyComponent).BaseType, GetType(CodeDomSerializer)), CodeDomSerializer)

         ' This is the simplest case, in which the class just calls the base class
         '  to do the work. 
         Return baseClassSerializer.Deserialize(manager, codeObject)
      End Function 'Deserialize

      Public Overrides Function Serialize(ByVal manager As IDesignerSerializationManager, _
                                            ByVal value As Object) As Object
         ' Associate the component with the serializer in the same manner as with
         '  Deserialize
         Dim baseClassSerializer As CodeDomSerializer = CType(manager.GetSerializer( _
                GetType(MyComponent).BaseType, GetType(CodeDomSerializer)), CodeDomSerializer)

         Dim codeObject As Object = baseClassSerializer.Serialize(manager, value)

         ' Anything could be in the codeObject.  This sample operates on a
         '  CodeStatementCollection.
         If TypeOf codeObject Is CodeStatementCollection Then
            Dim statements As CodeStatementCollection = CType(codeObject, CodeStatementCollection)

            ' The code statement collection is valid, so add a comment.
            Dim commentText As String = "This comment was added to this object by a custom serializer."
            Dim comment As New CodeCommentStatement(commentText)
            statements.Insert(0, comment)
         End If
         Return codeObject
      End Function 'Serialize
   End Class 'MyCodeDomSerializer

   <DesignerSerializer(GetType(MyCodeDomSerializer), GetType(CodeDomSerializer))> _
   Public Class MyComponent
      Inherits Component
      Private localProperty As String = "Component Property Value"

      Public Property LocalProp() As String
         Get
            Return localProperty
         End Get
         Set(ByVal Value As String)
            localProperty = Value
         End Set
      End Property
   End Class 'MyComponent

End Namespace

[C#] 
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;
            }
        }
    }

}

[C++] 
#using <mscorlib.dll>
#using <System.Drawing.dll>
#using <System.dll>
#using <System.Design.dll>
using namespace System;
using namespace System::CodeDom;
using namespace System::ComponentModel;
using namespace System::ComponentModel::Design;
using namespace System::ComponentModel::Design::Serialization;
using namespace System::Drawing;
using namespace System::Windows::Forms;

namespace CodeDomSerializerSample
{
    public __gc class MyComponent;
private __gc class MyCodeDomSerializer : public CodeDomSerializer {
public:
    Object* Deserialize(IDesignerSerializationManager* manager, Object* codeObject) {
        // This is how we associate the component with the serializer.
        CodeDomSerializer* baseClassSerializer = dynamic_cast<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);
    }

    Object* Serialize(IDesignerSerializationManager* manager, Object* value) {
        /* Associate the component with the serializer in the same manner as with
        Deserialize */
        CodeDomSerializer* baseClassSerializer = dynamic_cast<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 (dynamic_cast<CodeStatementCollection*>(codeObject)) {
            CodeStatementCollection* statements = dynamic_cast<CodeStatementCollection*>(codeObject);

            // The code statement collection is valid, so add a comment.
            String* commentText = S"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 __gc class MyComponent : public Component {
private:
    String* localProperty;
public:
    MyComponent() : localProperty(S"Component Property Value") {}
    __property String* get_LocalProperty() {
        return localProperty;
    }
    __property void set_LocalProperty( String* value ) {
        localProperty = value;
    }

};

}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.ComponentModel.Design.Serialization

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System (in System.dll)

See Also

IDesignerSerializationManager Members | System.ComponentModel.Design.Serialization Namespace | IServiceProvider

Show:
© 2015 Microsoft