CodeMemberField CodeMemberField CodeMemberField CodeMemberField Class

定義

表示型別欄位的宣告。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別的欄位。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() CodeMemberField() CodeMemberField()

初始化 CodeMemberField 類別的新執行個體。Initializes a new instance of the CodeMemberField class.

CodeMemberField(CodeTypeReference, String) CodeMemberField(CodeTypeReference, String) CodeMemberField(CodeTypeReference, String) CodeMemberField(CodeTypeReference, String)

使用指定的欄位型別和欄位名稱,初始化 CodeMemberField 類別的新執行個體。Initializes a new instance of the CodeMemberField class using the specified field type and field name.

CodeMemberField(String, String) CodeMemberField(String, String) CodeMemberField(String, String) CodeMemberField(String, String)

使用指定的欄位型別和欄位名稱,初始化 CodeMemberField 類別的新執行個體。Initializes a new instance of the CodeMemberField class using the specified field type and field name.

CodeMemberField(Type, String) CodeMemberField(Type, String) CodeMemberField(Type, String) CodeMemberField(Type, String)

使用指定的欄位型別和欄位名稱,初始化 CodeMemberField 類別的新執行個體。Initializes a new instance of the CodeMemberField class using the specified field type and field name.

屬性

Attributes Attributes Attributes Attributes

取得或設定成員的屬性 (Attribute)。Gets or sets the attributes of the member.

(Inherited from CodeTypeMember)
Comments Comments Comments Comments

取得型別成員的註解集合。Gets the collection of comments for the type member.

(Inherited from CodeTypeMember)
CustomAttributes CustomAttributes CustomAttributes CustomAttributes

取得或設定成員的自訂屬性。Gets or sets the custom attributes of the member.

(Inherited from CodeTypeMember)
EndDirectives EndDirectives EndDirectives EndDirectives

取得成員的結尾指示詞。Gets the end directives for the member.

(Inherited from CodeTypeMember)
InitExpression InitExpression InitExpression InitExpression

取得或設定欄位的初始化運算式。Gets or sets the initialization expression for the field.

LinePragma LinePragma LinePragma LinePragma

取得或設定型別成員陳述式 (Statement) 所在的行。Gets or sets the line on which the type member statement occurs.

(Inherited from CodeTypeMember)
Name Name Name Name

取得或設定成員的名稱。Gets or sets the name of the member.

(Inherited from CodeTypeMember)
StartDirectives StartDirectives StartDirectives StartDirectives

取得成員的開頭指示詞。Gets the start directives for the member.

(Inherited from CodeTypeMember)
Type Type Type Type

取得或設定欄位的類型。Gets or sets the type of the field.

UserData UserData UserData UserData

取得目前物件的使用者可定義資料。Gets the user-definable data for the current object.

(Inherited from CodeObject)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

適用於