MemberAttributes 列舉

定義

定義類別成員的成員屬性識別項。

public enum class MemberAttributes
public enum MemberAttributes
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public enum MemberAttributes
type MemberAttributes = 
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type MemberAttributes = 
Public Enum MemberAttributes
繼承
MemberAttributes
屬性

欄位

Abstract 1

抽象成員。

AccessMask 61440

存取遮罩。

Assembly 4096

相同組件中的任何類別皆可以存取的成員。

Const 5

常數成員。

Family 12288

成員,該成員的類別及衍生類別的家族內皆可以存取該成員。

FamilyAndAssembly 8192

成員,該成員的類別中以及相同組件的衍生類別中皆可以存取該成員。

FamilyOrAssembly 16384

成員,該成員的類別中、任何組件中該成員的衍生類別,以及相同組件的任何類別中皆可以存取該成員。

Final 2

無法在衍生類別中覆寫的成員。

New 16

New 成員。

Overloaded 256

Overloaded 成員。 某些語言 (例如 Visual Basic) 需要被明確指示的 Overloaded 成員。

Override 4

覆寫基底類別成員的成員。

Private 20480

Private 成員。

Public 24576

Public 成員。

ScopeMask 15

範圍遮罩。

Static 3

靜態成員。 在 Visual Basic 中,這就等同於 Shared 關鍵字。

VTableMask 240

VTable 遮罩。

範例

下列範例程式代碼示範如何使用 CodeMemberProperty 來定義 string 具有 getset 存取子的屬性。

// Declares a property of type String named StringProperty.
CodeMemberProperty^ property1 = gcnew CodeMemberProperty;
property1->Name = "StringProperty";
property1->Type = gcnew CodeTypeReference( "System.String" );
property1->Attributes = MemberAttributes::Public;
property1->GetStatements->Add( gcnew CodeMethodReturnStatement( gcnew CodeFieldReferenceExpression( gcnew CodeThisReferenceExpression,"testStringField" ) ) );
property1->SetStatements->Add( gcnew CodeAssignStatement( gcnew CodeFieldReferenceExpression( gcnew CodeThisReferenceExpression,"testStringField" ),gcnew CodePropertySetValueReferenceExpression ) );

// A C# code generator produces the following source code for the preceeding example code:
//       public virtual string StringProperty
//       {
//              get
//            {
//                return this.testStringField;
//            }
//            set
//            {
//                this.testStringField = value;
//            }
//       }
// Declares a property of type String named StringProperty.
CodeMemberProperty property1 = new CodeMemberProperty();
property1.Name = "StringProperty";
property1.Type = new CodeTypeReference("System.String");
property1.Attributes = MemberAttributes.Public;
property1.GetStatements.Add( new CodeMethodReturnStatement( new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "testStringField") ) );
property1.SetStatements.Add( new CodeAssignStatement( new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "testStringField"), new CodePropertySetValueReferenceExpression()));

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

//       public virtual string StringProperty
//       {
//              get
//            {
//                return this.testStringField;
//            }
//            set
//            {
//                this.testStringField = value;
//            }
//       }
' Declares a property of type String named StringProperty.
Dim property1 As New CodeMemberProperty()
property1.Name = "StringProperty"
property1.Type = New CodeTypeReference("System.String")
property1.Attributes = MemberAttributes.Public
property1.GetStatements.Add(New CodeMethodReturnStatement(New CodeFieldReferenceExpression(New CodeThisReferenceExpression(), "testStringField")))
property1.SetStatements.Add(New CodeAssignStatement(New CodeFieldReferenceExpression(New CodeThisReferenceExpression(), "testStringField"), New CodePropertySetValueReferenceExpression()))

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

'     Public Overridable Property StringProperty() As String
'         Get
'             Return Me.testStringField
'         End Get
'         Set(ByVal Value As String)
'             Me.testStringField = value
'         End Set
'     End Property

備註

列舉中 MemberAttributes 定義的標識碼可用來指出類別成員的範圍和存取屬性。

注意

沒有 Virtual 成員屬性。 成員是透過將成員的存取權設定為公用 () property1.Attributes = MemberAttributes.Public 而宣告為虛擬,而不需將其指定為 Final。 在 Visual Basic Public Overridable () 中,沒有 Final 旗標會使 C# (public virtual) overridable 的成員virtual。 若要避免將成員宣告為 virtualoverridable,請在 屬性中 Attributes 設定 Public 和 Final 旗標。 Attributes如需設定成員屬性的詳細資訊,請參閱 屬性。

注意

設定存取旗標的模式 (包含 、PrivateAssemblyFamily) 詞彙Public的旗標,是使用 AccessMask 遮罩來遮罩所有存取旗標,然後設定所需的存取旗標。 例如,將名為) 的 constructor1 建構函式識別為 公用的建構函式 (的程式代碼語句為 constructor1.Attributes = (constructor1.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;Attributes例如,將 屬性直接設定為存取旗標 (, constructor1.Attributes = MemberAttributes.Public;) 清除可能設定的所有其他旗標。 此模式也應該用於使用 ScopeMask 遮罩設定範圍旗標 (Abstract、Final、Static、Override 或 Const) 。

適用於

另請參閱