Diese Dokumentation wurde archiviert und wird nicht länger gepflegt.

IDesignerSerializationManager-Schnittstelle

Aktualisiert: November 2007

Stellt eine Schnittstelle bereit, mit der die Serialisierung zur Entwurfszeit verwaltet werden kann.

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

public interface IDesignerSerializationManager : IServiceProvider
public interface IDesignerSerializationManager extends IServiceProvider
public interface IDesignerSerializationManager extends IServiceProvider

Ein Designer kann IDesignerSerializationManager verwenden, um auf nützliche Dienste für die Verwaltung von Serialisierungsvorgängen zur Entwurfszeit zuzugreifen. Eine Klasse, die z. B. den Serialisierungs-Manager für den Designer implementiert, kann mit dieser Schnittstelle Objekte erstellen, Typen suchen, Objekte erkennen und die Serialisierung bestimmter Typen anpassen.

Im folgenden Beispiel wird die Verwendung von IDesignerSerializationManager zum Serialisieren und Deserialisieren von Code DOM-Anweisungen veranschaulicht.

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

}


import System.*;
import System.CodeDom.*;
import System.ComponentModel.*;
import System.ComponentModel.Design.*;
import System.ComponentModel.Design.Serialization.*;
import System.Drawing.*;
import System.Windows.Forms.*;


class MyCodeDomSerializer extends CodeDomSerializer
{
    public Object Deserialize(IDesignerSerializationManager manager,
        Object codeObject) {

        // This is how we associate the component with the serializer.
        CodeDomSerializer baseClassSerializer = (CodeDomSerializer)
            manager.GetSerializer(MyComponent.class.ToType().get_BaseType(),
            CodeDomSerializer.class.ToType());

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

    public Object Serialize(IDesignerSerializationManager manager,
        Object value)
    {
        /* Associate the component with the serializer in the same manner as 
            with Deserialize 
         */

        CodeDomSerializer baseClassSerializer = (CodeDomSerializer)
            manager.GetSerializer(MyComponent.class.ToType().
            get_BaseType(), CodeDomSerializer.class.ToType());
        Object codeObject = baseClassSerializer.Serialize(manager, value);

        /* Anything could be in the codeObject.  This sample operates on a
                CodeStatementCollection. 
         */

        if (codeObject instanceof 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;
    } //Serialize
} //MyCodeDomSerializer

/** @attribute DesignerSerializer(MyCodeDomSerializer.class,
  CodeDomSerializer.class)
 */

public class MyComponent extends Component
{
    private String localProperty = "Component Property Value";

    /** @property 
     */
    public String get_LocalProperty()
    {
        return localProperty;
    } //get_LocalProperty

    /** @property 
     */
    public void set_LocalProperty (String value )
    {
        localProperty = value;
    } //set_LocalProperty
} //MyComponent


Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

.NET Framework und .NET Compact Framework unterstützen nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen für .NET Framework.

.NET Framework

Unterstützt in: 3.5, 3.0, 2.0, 1.1, 1.0
Anzeigen: