Edytuj

Udostępnij za pośrednictwem


MemberAttributes Enum

Definition

Defines member attribute identifiers for class members.

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
Inheritance
MemberAttributes
Attributes

Fields

Name Value Description
Abstract 1

An abstract member.

Final 2

A member that cannot be overridden in a derived class.

Static 3

A static member. In Visual Basic, this is equivalent to the Shared keyword.

Override 4

A member that overrides a base class member.

Const 5

A constant member.

ScopeMask 15

A scope mask.

New 16

A new member.

VTableMask 240

A VTable mask.

Overloaded 256

An overloaded member. Some languages, such as Visual Basic, require overloaded members to be explicitly indicated.

Assembly 4096

A member that is accessible to any class within the same assembly.

FamilyAndAssembly 8192

A member that is accessible within its class, and derived classes in the same assembly.

Family 12288

A member that is accessible within the family of its class and derived classes.

FamilyOrAssembly 16384

A member that is accessible within its class, its derived classes in any assembly, and any class in the same assembly.

Private 20480

A private member.

Public 24576

A public member.

AccessMask 61440

An access mask.

Examples

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

Remarks

The identifiers defined in the MemberAttributes enumeration can be used to indicate the scope and access attributes of a class member.

Note

There is no Virtual member attribute. A member is declared virtual by setting its member access to Public (property1.Attributes = MemberAttributes.Public) without specifying it as Final. The absence of the Final flag makes a member virtual in C# (public virtual), overridable in Visual Basic (Public Overridable). To avoid declaring the member as virtual or overridable, set both the Public and Final flags in the Attributes property. See the Attributes property for more information on setting member attributes.

Note

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. For example, the code statement to identify a constructor (named constructor1) as public is constructor1.Attributes = (constructor1.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;. Setting the Attributes property directly to an access flag (for example, constructor1.Attributes = MemberAttributes.Public;) erases all other flags that might be set. This pattern should also be used for setting the scope flags (Abstract, Final, Static, Override or Const) using the ScopeMask mask.

Applies to

See also