MemberAttributes MemberAttributes MemberAttributes MemberAttributes Enum

定義

定義類別成員的成員屬性識別項。Defines member attribute identifiers for class members.

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

欄位

Abstract Abstract Abstract Abstract 1

抽象成員。An abstract member.

AccessMask AccessMask AccessMask AccessMask 61440

存取遮罩。An access mask.

Assembly Assembly Assembly Assembly 4096

相同組件中的任何類別皆可以存取的成員。A member that is accessible to any class within the same assembly.

Const Const Const Const 5

常數成員。A constant member.

Family Family Family Family 12288

成員,該成員的類別及衍生類別的家族內皆可以存取該成員。A member that is accessible within the family of its class and derived classes.

FamilyAndAssembly FamilyAndAssembly FamilyAndAssembly FamilyAndAssembly 8192

成員,該成員的類別中以及相同組件的衍生類別中皆可以存取該成員。A member that is accessible within its class, and derived classes in the same assembly.

FamilyOrAssembly FamilyOrAssembly FamilyOrAssembly FamilyOrAssembly 16384

成員,該成員的類別中、任何組件中該成員的衍生類別,以及相同組件的任何類別中皆可以存取該成員。A member that is accessible within its class, its derived classes in any assembly, and any class in the same assembly.

Final Final Final Final 2

無法在衍生類別中覆寫的成員。A member that cannot be overridden in a derived class.

New New New New 16

New 成員。A new member.

Overloaded Overloaded Overloaded Overloaded 256

Overloaded 成員。An overloaded member. 某些語言 (例如 Visual Basic) 需要被明確指示的 Overloaded 成員。Some languages, such as Visual Basic, require overloaded members to be explicitly indicated.

Override Override Override Override 4

覆寫基底類別成員的成員。A member that overrides a base class member.

Private Private Private Private 20480

Private 成員。A private member.

Public Public Public Public 24576

Public 成員。A public member.

ScopeMask ScopeMask ScopeMask ScopeMask 15

範圍遮罩。A scope mask.

Static Static Static Static 3

靜態成員。A static member. 在 Visual Basic 中,這就等同於 Shared 關鍵字。In Visual Basic, this is equivalent to the Shared keyword.

VTableMask VTableMask VTableMask VTableMask 240

VTable 遮罩。A VTable mask.

範例

下列範例程式CodeMemberProperty代碼示範如何使用來定義具有getstring set存取子的屬性。The following example code demonstrates use of a CodeMemberProperty to define a string property with get and set accessors.

// 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列舉中定義的識別碼可以用來表示類別成員的範圍和存取屬性。The identifiers defined in the MemberAttributes enumeration can be used to indicate the scope and access attributes of a class member.

注意

Virtual沒有成員屬性。There is no Virtual member attribute. 成員已宣告為虛擬, 其方式是將其成員存取property1.Attributes = MemberAttributes.Public權設定為 Public (), 而不將其指定為最終。A member is declared virtual by setting its member access to Public (property1.Attributes = MemberAttributes.Public) without specifying it as Final. 如果沒有最後一個旗標virtual , overridable則會在C# Visual Basicpublic virtual(Public Overridable) 中建立成員 ()。The absence of the Final flag makes a member virtual in C# (public virtual), overridable in Visual Basic (Public Overridable). 若要避免將成員宣告virtualoverridable或, 請在Attributes屬性中設定 Public 和 Final 旗標。To avoid declaring the member as virtual or overridable, set both the Public and Final flags in the Attributes property. 如需設定成員屬性的詳細資訊, 請參閱屬性。AttributesSee the Attributes property for more information on setting member attributes.

注意

設定存取旗標 ( Public包含詞彙AssemblyPrivate、或Family的旗標) 的模式是使用 AccessMask mask 遮罩所有存取旗標, 然後設定所需的存取旗標。The pattern for setting the access flags (flags containing the terms Public, Private, Assembly, or Family) is to mask out all access flags using the AccessMask mask and then set the desired access flag. 例如, 用來識別公用程式 (名constructor1為) 的程式碼語句是。 constructor1.Attributes = (constructor1.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;For example, the code statement to identify a constructor (named constructor1) as public is constructor1.Attributes = (constructor1.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;. 將屬性直接設定為存取旗標 (例如, constructor1.Attributes = MemberAttributes.Public;) 會清除可能設定的所有其他旗標。 AttributesSetting the Attributes property directly to an access flag (for example, constructor1.Attributes = MemberAttributes.Public;) erases all other flags that might be set. 此模式也應該用於使用 ScopeMask mask 設定範圍旗標 (Abstract、Final、Static、Override 或 Const)。This pattern should also be used for setting the scope flags (Abstract, Final, Static, Override or Const) using the ScopeMask mask.

適用於

另請參閱