CodeMemberField クラス

定義

型のフィールドの宣言を表します。Represents a declaration for a field of a type.

public ref class CodeMemberField : System::CodeDom::CodeTypeMember
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Serializable]
public class CodeMemberField : System.CodeDom.CodeTypeMember
type CodeMemberField = class
    inherit CodeTypeMember
Public Class CodeMemberField
Inherits CodeTypeMember
継承
CodeMemberField
属性

次の例では、testStringFieldという名前の string 型のフィールドを宣言するために CodeMemberField を使用する方法を示します。The following example demonstrates use of a CodeMemberField to declare a field of type string named testStringField.

// Declares a type to contain a field and a constructor method.
CodeTypeDeclaration^ type1 = gcnew CodeTypeDeclaration( "FieldTest" );

// Declares a field of type String named testStringField.
CodeMemberField^ field1 = gcnew CodeMemberField( "System.String","TestStringField" );
type1->Members->Add( field1 );

// Declares an empty type constructor.
CodeConstructor^ constructor1 = gcnew CodeConstructor;
constructor1->Attributes = MemberAttributes::Public;
type1->Members->Add( constructor1 );

// A C# code generator produces the following source code for the preceeding example code:
//    public class FieldTest 
//    {
//      private string testStringField;
//        
//        public FieldTest() 
//        {
//        }                            
//    }            
// Declares a type to contain a field and a constructor method.
CodeTypeDeclaration type1 = new CodeTypeDeclaration("FieldTest");

// Declares a field of type String named testStringField.
CodeMemberField field1 = new CodeMemberField("System.String", "TestStringField");
type1.Members.Add( field1 );

// Declares an empty type constructor.
CodeConstructor constructor1 = new CodeConstructor();
constructor1.Attributes = MemberAttributes.Public;            
type1.Members.Add( constructor1 );

// A C# code generator produces the following source code for the preceeding example code:

//    public class FieldTest 
//    {
//      private string testStringField;
//        
//        public FieldTest() 
//        {
//        }                            
//    }            
' Declares a type to contain a field and a constructor method.
Dim type1 As New CodeTypeDeclaration("FieldTest")

' Declares a field of type String named testStringField.
Dim field1 As New CodeMemberField("System.String", "testStringField")
type1.Members.Add(field1)

' Declares an empty type constructor.
Dim constructor1 As New CodeConstructor()
constructor1.Attributes = MemberAttributes.Public
type1.Members.Add(constructor1)

' A Visual Basic code generator produces the following source code for the preceeding example code:

' Public Class FieldTest
'
'     Private TestStringField As String
'
'     Public Sub New()
'         MyBase.New()
'     End Sub
'
' End Class

// This example demonstrates declaring a public constant type member field.

// When declaring a public constant type member field, you must set a particular
// access and scope mask to the member attributes of the field in order for the
// code generator to properly generate the field as a constant field.

// Declares an integer field using a CodeMemberField
CodeMemberField^ constPublicField = gcnew CodeMemberField( int::typeid,"testConstPublicField" );

// Resets the access and scope mask bit flags of the member attributes of the field
// before setting the member attributes of the field to public and constant.
constPublicField->Attributes = (MemberAttributes)((constPublicField->Attributes &  ~MemberAttributes::AccessMask &  ~MemberAttributes::ScopeMask) | MemberAttributes::Public | MemberAttributes::Const);
// This example demonstrates declaring a public constant type member field.

// When declaring a public constant type member field, you must set a particular
// access and scope mask to the member attributes of the field in order for the
// code generator to properly generate the field as a constant field.

// Declares an integer field using a CodeMemberField
CodeMemberField constPublicField = new CodeMemberField(typeof(int), "testConstPublicField");

// Resets the access and scope mask bit flags of the member attributes of the field
// before setting the member attributes of the field to public and constant.
constPublicField.Attributes = (constPublicField.Attributes & ~MemberAttributes.AccessMask & ~MemberAttributes.ScopeMask) | MemberAttributes.Public | MemberAttributes.Const;
' This example demonstrates declaring a public constant type member field.
' When declaring a public constant type member field, you must set a particular
' access and scope mask to the member attributes of the field in order for the
' code generator to properly generate the field as a constant field.
' Declares an integer field using a CodeMemberField
Dim constPublicField As New CodeMemberField(GetType(Integer), "testConstPublicField")

' Resets the access and scope mask bit flags of the member attributes of the field
' before setting the member attributes of the field to public and constant.
constPublicField.Attributes = constPublicField.Attributes And Not MemberAttributes.AccessMask And Not MemberAttributes.ScopeMask Or MemberAttributes.Public Or MemberAttributes.Const

注釈

CodeMemberField は、型のフィールドの宣言を表すために使用できます。CodeMemberField can be used to represent the declaration for a field of a type.

コンストラクター

CodeMemberField()

CodeMemberField クラスの新しいインスタンスを初期化します。Initializes a new instance of the CodeMemberField class.

CodeMemberField(CodeTypeReference, String)

フィールドの種類とフィールド名を指定して、CodeMemberField クラスの新しいインスタンスを初期化します。Initializes a new instance of the CodeMemberField class using the specified field type and field name.

CodeMemberField(String, String)

フィールドの種類とフィールド名を指定して、CodeMemberField クラスの新しいインスタンスを初期化します。Initializes a new instance of the CodeMemberField class using the specified field type and field name.

CodeMemberField(Type, String)

フィールドの種類とフィールド名を指定して、CodeMemberField クラスの新しいインスタンスを初期化します。Initializes a new instance of the CodeMemberField class using the specified field type and field name.

プロパティ

Attributes

メンバーの属性を取得または設定します。Gets or sets the attributes of the member.

(継承元 CodeTypeMember)
Comments

型メンバーのコメント コレクションを取得します。Gets the collection of comments for the type member.

(継承元 CodeTypeMember)
CustomAttributes

メンバーのカスタム属性を取得または設定します。Gets or sets the custom attributes of the member.

(継承元 CodeTypeMember)
EndDirectives

メンバーの終了ディレクティブを取得します。Gets the end directives for the member.

(継承元 CodeTypeMember)
InitExpression

フィールドの初期化式を取得または設定します。Gets or sets the initialization expression for the field.

LinePragma

型メンバーのステートメントが発生する行を取得または設定します。Gets or sets the line on which the type member statement occurs.

(継承元 CodeTypeMember)
Name

メンバーの名前を取得または設定します。Gets or sets the name of the member.

(継承元 CodeTypeMember)
StartDirectives

メンバーの開始ディレクティブを取得します。Gets the start directives for the member.

(継承元 CodeTypeMember)
Type

フィールドの型を取得または設定します。Gets or sets the type of the field.

UserData

現在のオブジェクトのユーザー定義可能なデータを取得します。Gets the user-definable data for the current object.

(継承元 CodeObject)

メソッド

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判定します。Determines whether the specified object is equal to the current object.

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。Serves as the default hash function.

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。Gets the Type of the current instance.

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object.

(継承元 Object)
ToString()

現在のオブジェクトを表す string を返します。Returns a string that represents the current object.

(継承元 Object)

適用対象