共用方式為


IDesignerSerializationManager 介面

定義

提供可以管理設計階段序列化 (Serialization) 的介面。

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)

從相依性插入容器取得假的重構函式收集器實例。

適用於

另請參閱