IDesignerSerializationManager 接口

定义

提供可以管理设计时序列化的接口。

public interface class IDesignerSerializationManager : IServiceProvider
public interface IDesignerSerializationManager : IServiceProvider
type IDesignerSerializationManager = interface
    interface IServiceProvider
Public Interface IDesignerSerializationManager
Implements IServiceProvider
派生
实现

示例

下面的示例演示如何使用 IDesignerSerializationManager 序列化和反序列化 Code DOM 语句。

#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

注解

设计器可以利用 IDesignerSerializationManager 来访问对管理设计时序列化过程有用的服务。 例如,实现设计器序列化管理器的类可以使用此接口来创建对象、查找类型、标识对象以及自定义特定类型的序列化。

属性

Context

获取基于堆栈的、用户定义的存储区域,该区域对于序列化程序之间的通信十分有用。

Properties

指示可利用可用序列化程序进行序列化的自定义属性。

方法

AddSerializationProvider(IDesignerSerializationProvider)

向序列化管理器添加指定的序列化提供程序。

CreateInstance(Type, ICollection, String, Boolean)

创建指定类型的实例并将其添加到已命名实例的集合中。

GetInstance(String)

获取指定名称的已创建对象的实例,如果该对象不存在则为 null

GetName(Object)

获取指定对象的名称,如果该对象不具有名称则为 null

GetSerializer(Type, Type)

为指定对象类型获取所请求类型的序列化程序。

GetService(Type)

获取指定类型的服务对象。

(继承自 IServiceProvider)
GetType(String)

获取指定名称的类型。

RemoveSerializationProvider(IDesignerSerializationProvider)

从序列化管理器移除自定义的序列化提供程序。

ReportError(Object)

报告序列化中的错误。

SetName(Object, String)

设置指定的现有对象的名称。

事件

ResolveName

GetName(Object) 无法在序列化管理器的名称表中找到指定名称时发生。

SerializationComplete

在序列化完成时发生。

扩展方法

GetKeyedService<T>(IServiceProvider, Object)

IServiceProvider获取 类型的T服务。

GetKeyedServices(IServiceProvider, Type, Object)

IServiceProvider获取 类型的serviceType服务的枚举。

GetKeyedServices<T>(IServiceProvider, Object)

IServiceProvider获取 类型的T服务的枚举。

GetRequiredKeyedService(IServiceProvider, Type, Object)

IServiceProvider获取 类型的serviceType服务。

GetRequiredKeyedService<T>(IServiceProvider, Object)

IServiceProvider获取 类型的T服务。

CreateAsyncScope(IServiceProvider)

新建可用于解析作用域内服务的 AsyncServiceScope

CreateScope(IServiceProvider)

新建可用于解析作用域内服务的 IServiceScope

GetRequiredService(IServiceProvider, Type)

IServiceProvider 获取类型 serviceType 的服务。

GetRequiredService<T>(IServiceProvider)

IServiceProvider 获取类型 T 的服务。

GetService<T>(IServiceProvider)

IServiceProvider 获取类型 T 的服务。

GetServices(IServiceProvider, Type)

IServiceProvider 获取 serviceType 类型服务的枚举。

GetServices<T>(IServiceProvider)

IServiceProvider 获取 T 类型服务的枚举。

GetFakeLogCollector(IServiceProvider)

获取对象,该对象收集发送到假记录器中的日志记录。

GetFakeRedactionCollector(IServiceProvider)

从依赖项注入容器中获取假的重设函数收集器实例。

适用于

另请参阅