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

Новый элемент.

Overloaded 256

Перегруженный элемент. В некоторых языках, например в Visual Basic, необходимо явно указывать перегруженные члены.

Override 4

Элемент, переопределяющий элемент базового класса.

Private 20480

Закрытый элемент.

Public 24576

Открытый элемент.

ScopeMask 15

Маска области.

Static 3

Статический элемент. (Эквивалентно ключевому слову Shared в Visual Basic).

VTableMask 240

Маска VTable.

Примеры

В следующем примере кода показано использование a CodeMemberProperty для определения string свойства с get помощью методов доступа и set управления доступом.

// 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 делает элемент virtual в C# (public virtual) overridable в Visual Basic (Public Overridable). Чтобы избежать объявления элемента как virtual или overridable, задайте флаги Public и Final в свойстве Attributes . Дополнительные сведения о настройке атрибутов элементов см. в Attributes свойстве.

Примечание

Шаблон настройки флагов доступа (флагов, содержащих терминыPublic, Private``AssemblyилиFamily) заключается в том, чтобы маскировать все флаги доступа с помощью маски AccessMask, а затем задать нужный флаг доступа. Например, оператор кода для идентификации конструктора (с именем constructor1) как открытый constructor1.Attributes = (constructor1.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;. Attributes Установка свойства непосредственно на флаг доступа (например, constructor1.Attributes = MemberAttributes.Public;) удаляет все другие флаги, которые могут быть заданы. Этот шаблон также следует использовать для настройки флагов области (Abstract, Final, Static, Override или Const) с помощью маски ScopeMask.

Применяется к

См. также раздел