Export (0) Print
Expand All
Expand Minimize

MemberAttributes Enumeration

Defines member attribute identifiers for class members.

Namespace: System.CodeDom
Assembly: System (in system.dll)

[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public enum MemberAttributes
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public enum MemberAttributes
SerializableAttribute 
ComVisibleAttribute(true) 
public enum MemberAttributes

 Member nameDescription
AbstractAn abstract member. 
AccessMaskAn access mask. 
AssemblyA member that is accessible to any class within the same assembly. 
ConstA constant member. 
FamilyA member that is accessible within the family of its class and derived classes. 
FamilyAndAssemblyA member that is accessible within its class, and derived classes in the same assembly. 
FamilyOrAssemblyA member that is accessible within its class, its derived classes in any assembly, and any class in the same assembly. 
FinalA member that cannot be overridden in a derived class. 
NewA new member. 
OverloadedAn overloaded member. Some languages, such as Visual Basic, require overloaded members to be explicitly indicated. 
OverrideA member that overrides a base class member. 
PrivateA private member. 
PublicA public member. 
ScopeMaskA scope mask. 
StaticA static member. In Visual Basic, this is equivalent to the Shared keyword. 
VTableMaskA VTable mask. 

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

NoteNote:

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), overrideable in Visual Basic (Public Overrideable). To avoid declaring the member as virtual or overrideable, set both the Public and Final flags in the Attributes property. See the Attributes property for more information on setting member attributes.

NoteNote:

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.

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 = 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.
CodeMemberProperty property1 = new CodeMemberProperty();
property1.set_Name("StringProperty");
property1.set_Type(new CodeTypeReference("System.String"));
property1.set_Attributes(MemberAttributes.Public);
property1.get_GetStatements().Add(new CodeMethodReturnStatement(new
    CodeFieldReferenceExpression(new CodeThisReferenceExpression(),
    "testStringField")));
property1.get_SetStatements().Add(new CodeAssignStatement(new 
    CodeFieldReferenceExpression(new CodeThisReferenceExpression(),
    "testStringField"), new CodePropertySetValueReferenceExpression()));
//  /** @property 
//   */
//  public   String get_StringProperty()
//  {
//      return this.get_testStringField();
//  } //get_StringProperty
//
//  /** @property 
//   */
//  public void set_StringProperty (String value )
//  {
//      this.set_testStringField(value);
//  } //set_StringProperty

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft