IDesignerSerializationManager IDesignerSerializationManager IDesignerSerializationManager IDesignerSerializationManager Interface

Definizione

Fornisce un'interfaccia in grado di gestire la serializzazione in fase di progettazione.Provides an interface that can manage design-time serialization.

public interface class IDesignerSerializationManager : IServiceProvider
public interface IDesignerSerializationManager : IServiceProvider
type IDesignerSerializationManager = interface
    interface IServiceProvider
Public Interface IDesignerSerializationManager
Implements IServiceProvider
Derivato
Implementazioni

Esempi

Nell'esempio seguente viene illustrato come utilizzare IDesignerSerializationManager per serializzare e deserializzare le istruzioni code DOM.The following example illustrates how to use IDesignerSerializationManager to serialize and deserialize Code DOM statements.

#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
{
   ref class MyComponent;
   private ref class MyCodeDomSerializer: public CodeDomSerializer
   {
   public:
      Object^ Deserialize( IDesignerSerializationManager^ manager, Object^ codeObject ) new
      {
         // This is how we associate the component with the serializer.
         CodeDomSerializer^ baseClassSerializer = (CodeDomSerializer^)(
            manager->GetSerializer(
               MyComponent::typeid->BaseType, CodeDomSerializer::typeid ));
         
         /* 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 ) new
      {
         /* Associate the component with the serializer in the same manner as with
            Deserialize */
         CodeDomSerializer^ baseClassSerializer = (CodeDomSerializer^)(
            manager->GetSerializer(
               MyComponent::typeid->BaseType, CodeDomSerializer::typeid ));

         Object^ codeObject = baseClassSerializer->Serialize( manager, value );
         
         /* Anything could be in the codeObject.  This sample operates on a
            CodeStatementCollection. */
         if ( (CodeStatementCollection^)(codeObject) )
         {
            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 = gcnew CodeCommentStatement( commentText );
            statements->Insert( 0, comment );
         }
         return codeObject;
      }
   };

   [DesignerSerializer(CodeDomSerializerSample::MyCodeDomSerializer::typeid,
      CodeDomSerializer::typeid)]
   public ref class MyComponent: public Component
   {
   private:
      String^ localProperty;

   public:
      MyComponent()
      {
         localProperty = "Component Property Value";
      }

      property String^ LocalProperty 
      {
         String^ get()
         {
            return localProperty;
         }
         void set( String^ value )
         {
            localProperty = value;
         }
      }
   };
}
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;
            }
        }
    }

}
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

   <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

End Namespace

Commenti

Una finestra IDesignerSerializationManager di progettazione può utilizzare per accedere ai servizi utili per la gestione dei processi di serializzazione in fase di progettazione.A designer can utilize IDesignerSerializationManager to access services useful to managing design-time serialization processes. Ad esempio, una classe che implementa il gestore della serializzazione della finestra di progettazione può utilizzare questa interfaccia per creare oggetti, cercare tipi, identificare oggetti e personalizzare la serializzazione di tipi particolari.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.

Proprietà

Context Context Context Context

Ottiene un'area di memorizzazione definita dall'utente e basata su stack utile per la comunicazione tra i serializzatori.Gets a stack-based, user-defined storage area that is useful for communication between serializers.

Properties Properties Properties Properties

Indica proprietà personalizzate che possono essere serializzate con i serializzatori disponibili.Indicates custom properties that can be serializable with available serializers.

Metodi

AddSerializationProvider(IDesignerSerializationProvider) AddSerializationProvider(IDesignerSerializationProvider) AddSerializationProvider(IDesignerSerializationProvider) AddSerializationProvider(IDesignerSerializationProvider)

Aggiunge il provider di serializzazione specificato al gestore della serializzazione.Adds the specified serialization provider to the serialization manager.

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

Crea un'istanza del tipo specificato e la aggiunge a una raccolta di istanze denominate.Creates an instance of the specified type and adds it to a collection of named instances.

GetInstance(String) GetInstance(String) GetInstance(String) GetInstance(String)

Ottiene un'istanza di un oggetto creato con il nome specificato oppure null se tale oggetto non esiste.Gets an instance of a created object of the specified name, or null if that object does not exist.

GetName(Object) GetName(Object) GetName(Object) GetName(Object)

Ottiene il nome dell'oggetto specificato oppure null se l'oggetto non ha alcun nome.Gets the name of the specified object, or null if the object has no name.

GetSerializer(Type, Type) GetSerializer(Type, Type) GetSerializer(Type, Type) GetSerializer(Type, Type)

Ottiene un serializzatore del tipo richiesto per il tipo di oggetto specificato.Gets a serializer of the requested type for the specified object type.

GetService(Type) GetService(Type) GetService(Type) GetService(Type)

Ottiene l'oggetto Service del tipo specificato.Gets the service object of the specified type.

(Inherited from IServiceProvider)
GetType(String) GetType(String) GetType(String) GetType(String)

Ottiene un tipo del nome specificato.Gets a type of the specified name.

RemoveSerializationProvider(IDesignerSerializationProvider) RemoveSerializationProvider(IDesignerSerializationProvider) RemoveSerializationProvider(IDesignerSerializationProvider) RemoveSerializationProvider(IDesignerSerializationProvider)

Rimuove un provider di serializzazione personalizzato dal gestore della serializzazione.Removes a custom serialization provider from the serialization manager.

ReportError(Object) ReportError(Object) ReportError(Object) ReportError(Object)

Riporta un errore di serializzazione.Reports an error in serialization.

SetName(Object, String) SetName(Object, String) SetName(Object, String) SetName(Object, String)

Imposta il nome dell'oggetto esistente specificato.Sets the name of the specified existing object.

Eventi

ResolveName ResolveName ResolveName ResolveName

Viene generato quando il metodo GetName(Object) non è in grado di individuare il nome specificato nella tabella dei nomi del gestore della serializzazione.Occurs when GetName(Object) cannot locate the specified name in the serialization manager's name table.

SerializationComplete SerializationComplete SerializationComplete SerializationComplete

Viene generato al termine della serializzazione.Occurs when serialization is complete.

Si applica a

Vedi anche