แก้ไข

แชร์ผ่าน


CodeTypeDeclaration.TypeAttributes Property

Definition

Gets or sets the attributes of the type.

public:
 property System::Reflection::TypeAttributes TypeAttributes { System::Reflection::TypeAttributes get(); void set(System::Reflection::TypeAttributes value); };
public System.Reflection.TypeAttributes TypeAttributes { get; set; }
member this.TypeAttributes : System.Reflection.TypeAttributes with get, set
Public Property TypeAttributes As TypeAttributes

Property Value

A TypeAttributes object that indicates the attributes of the type.

Remarks

The TypeAttributes property contains the same type of values used by System.Reflection when investigating a type at run time. Many of these flags do not correspond to the type declaration syntax for some languages. As a result, only the following flags are significant to CodeTypeDeclaration : Class, Interface, Abstract, Sealed, Public, NotPublic, NestedPublic, and NestedPrivate.

Note

Some of the flags such as Abstract overlap with the meaning of flags in the Attributes property of CodeTypeDeclaration that is inherited from CodeTypeMember. The Attributes property is a side effect of the CodeTypeDeclaration class inheriting from CodeTypeMember so that classes can be nested. The flags in the TypeAttributes property should be used instead of the flags in the Attributes property.

Note

The pattern for setting the visibility flags (flags containing the words Public or Nested) is to mask out all visibility flags using the VisibilityMask and then set the desired visibility flag. For example, the C# code statement to identify the CodeTypeDeclaration (named cd) as an internal class is cd.TypeAttributes = (cd.TypeAttributes & ~TypeAttributes.VisibilityMask) | TypeAttributes.NotPublic;. The code to set the same value in Visual Basic is cd.TypeAttributes = (cd.TypeAttributes And (TypeAttributes.VisibilityMask Xor -1)) Or TypeAttributes.NotPublic. Setting the TypeAttributes property directly to a visibility flag (cd.TypeAttributes = TypeAttributes.NotPublic;) erases all other flags that might be set.

Applies to

See also