CodeDomSerializer クラスとは? わかりやすく解説

CodeDomSerializer クラス

オブジェクト グラフ一連の CodeDOM ステートメントシリアル化ます。このクラスは、シリアライザの抽象基本クラス提供します

名前空間: System.ComponentModel.Design.Serialization
アセンブリ: System.Design (system.design.dll 内)
構文構文

Public Class CodeDomSerializer
    Inherits CodeDomSerializerBase
Dim instance As CodeDomSerializer
public class CodeDomSerializer : CodeDomSerializerBase
public ref class CodeDomSerializer : public
 CodeDomSerializerBase
public class CodeDomSerializer extends CodeDomSerializerBase
public class CodeDomSerializer extends
 CodeDomSerializerBase
解説解説

カスタム CodeDomSerializer実装すると、デザイン時にコンポーネントの型に対応するコンポーネント初期化コード生成制御できます

ある型に対すカスタム CodeDomSerializer実装するには、次の処理を実行する必要があります

  1. CodeDomSerializer から派生するクラス定義します

  2. シリアル化や逆シリアル化の各メソッドメソッド オーバーライド実装します (詳細については、以下を参照してください)。

  3. DesignerSerializerAttribute を使用してカスタム CodeDomSerializer 実装コンポーネントの型に関連付けます。

コンポーネント構成コード生成するためのシリアル化メソッド実装するには、次の手順従います

  1. CodeDomSerializer から派生したクラス内で、基本クラス該当するシリアル化または逆シリアル化メソッドオーバーライドます。

  2. 既定コンポーネント構成実行するコード ステートメント生成する既定のシリアライザが必要な場合は、コンポーネント基本シリアライザを取得して呼び出します。コンポーネント基本シリアライザを取得するには、メソッド オーバーライド渡される IDesignerSerializationManager の GetSerializer メソッド呼び出します。要求するシリアライザの基本型 (CodeDomSerializer) と共に構成シリアル化するコンポーネントの型を GetSerializer メソッド渡しますIDesignerSerializationManagerメソッド オーバーライド渡されるオブジェクト使用してオーバーライドする同じ名前のメソッド基本シリアライザで呼び出します。Serialize メソッド実装する場合基本シリアライザの Serialize メソッドオブジェクト返します。このオブジェクトの型は基本シリアライザの型に依存し基本シリアライザの型は値をシリアル化するコンポーネントの型に依存します。SerializeEvents メソッド、SerializeProperties メソッド、または SerializePropertiesToResources メソッド実装する場合生成されるコード ステートメント格納する新しい CodeStatementCollection を作成し、それをメソッドに渡す必要があります

  3. 基本シリアライザ メソッド呼び出すと、コンポーネント初期化するために生成されるステートメント格納した CodeStatementCollection得られます。それ以外場合は、CodeStatementCollection作成する必要がありますコンポーネント構成コード生成されるステートメントを表す CodeStatement オブジェクトをこのコレクション追加できます

  4. コンポーネント構成するために生成されるソース コードを表す CodeStatementCollection返します

継承時の注意 CodeDomSerializer から継承する場合は、Deserialize および Serialize の両メンバオーバーライドする必要があります

使用例使用例

CodeDomSerializer から派生したカスタム CodeDOM シリアライザを作成する方法次のコード例示します

Imports System
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 'MyCodeDomSerializer

   <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 'MyComponent

End Namespace
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
継承階層継承階層
System.Object
   System.ComponentModel.Design.Serialization.CodeDomSerializerBase
    System.ComponentModel.Design.Serialization.CodeDomSerializer
       System.ComponentModel.Design.Serialization.CollectionCodeDomSerializer
       System.Windows.Forms.Design.ImageListCodeDomSerializer
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
CodeDomSerializer メンバ
System.ComponentModel.Design.Serialization 名前空間
DesignerSerializerAttribute
その他の技術情報
動的なソース コード生成コンパイル



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「CodeDomSerializer クラス」の関連用語

CodeDomSerializer クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



CodeDomSerializer クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS