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

シリアル化が完了したときに発生します。

拡張メソッド

名前 説明
CreateAsyncScope(IServiceProvider)

スコープ付きサービスの解決に使用できる新しい AsyncServiceScope を作成します。

CreateScope(IServiceProvider)

スコープ付きサービスの解決に使用できる新しい IServiceScope を作成します。

GetKeyedService(IServiceProvider, Type, Object)

serviceTypeからIServiceProvider型のサービスを取得します。

GetKeyedService<T>(IServiceProvider, Object)

TからIServiceProvider型のサービスを取得します。

GetKeyedServices(IServiceProvider, Type, Object)

serviceTypeからIServiceProvider型のサービスの列挙体を取得します。

GetKeyedServices<T>(IServiceProvider, Object)

TからIServiceProvider型のサービスの列挙体を取得します。

GetRequiredKeyedService(IServiceProvider, Type, Object)

serviceTypeからIServiceProvider型のサービスを取得します。

GetRequiredKeyedService<T>(IServiceProvider, Object)

TからIServiceProvider型のサービスを取得します。

GetRequiredService(IServiceProvider, Type)

serviceTypeからIServiceProvider型のサービスを取得します。

GetRequiredService<T>(IServiceProvider)

TからIServiceProvider型のサービスを取得します。

GetService<T>(IServiceProvider)

TからIServiceProvider型のサービスを取得します。

GetServices(IServiceProvider, Type)

serviceTypeからIServiceProvider型のサービスの列挙体を取得します。

GetServices<T>(IServiceProvider)

TからIServiceProvider型のサービスの列挙体を取得します。

適用対象

こちらもご覧ください