Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Type.Attributes Property

Gets the attributes associated with the Type.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public TypeAttributes Attributes { get; }

Property Value

Type: System.Reflection.TypeAttributes
A TypeAttributes object representing the attribute set of the Type, unless the Type represents a generic type parameter, in which case the value is unspecified.

If the current Type represents a constructed generic type, this property returns the attributes of the generic type definition. For example, the attributes returned for MyGenericClass<int> (MyGenericClass(Of Integer) in Visual Basic) are the attributes of MyGenericClass<T> (MyGenericClass(Of T) in Visual Basic).

If the current Type represents a generic type parameter — that is, if the IsGenericParameter property returns true — the TypeAttributes value returned by this property is unspecified.

The following example shows the use of the Type.Attributes property. The fact that there is a member in each of several groupings that has the value zero means that you must use masks before testing for those members.

For most purposes, properties like IsClass, IsAutoLayout, and IsSpecialName are easier to use than type attributes.

using System;
using System.Reflection;

internal struct S
    public int X;

public abstract class Example
    protected sealed class NestedClass {}

    public interface INested {}

    private static System.Windows.Controls.TextBlock outputBlock;

    public static void Demo(System.Windows.Controls.TextBlock outputBlock)
        Example.outputBlock = outputBlock;


    private static void DisplayAttributes(Type t)
        outputBlock.Text += "Attributes for type "+t.Name+":\n";

        TypeAttributes attr = t.Attributes;

        // To test for visibility attributes, you must use the visibility
        // mask.
        TypeAttributes visibility = attr & TypeAttributes.VisibilityMask;
        switch (visibility)
            case TypeAttributes.NotPublic:
                outputBlock.Text += " not public\n";
            case TypeAttributes.Public:
                outputBlock.Text += " public\n";
            case TypeAttributes.NestedPublic:
                outputBlock.Text += " nested and public\n";
            case TypeAttributes.NestedPrivate:
                outputBlock.Text += " nested and private\n";
            case TypeAttributes.NestedFamANDAssem:
                outputBlock.Text += " nested, and inheritable only within the assembly" +
                   "\n         (cannot be declared in C#)\n";
            case TypeAttributes.NestedAssembly:
                outputBlock.Text += " nested and internal\n";
            case TypeAttributes.NestedFamily:
                outputBlock.Text += " nested and protected\n";
            case TypeAttributes.NestedFamORAssem:
                outputBlock.Text += " nested and protected internal\n";

        TypeAttributes layout = attr & TypeAttributes.LayoutMask;
        switch (layout)
            case TypeAttributes.AutoLayout:
                outputBlock.Text += " AutoLayout\n";
            case TypeAttributes.SequentialLayout:
                outputBlock.Text += " SequentialLayout\n";
            case TypeAttributes.ExplicitLayout:
                outputBlock.Text += " ExplicitLayout\n";

        TypeAttributes classSemantics = attr & TypeAttributes.ClassSemanticsMask;
        switch (classSemantics)
            case TypeAttributes.Class:
                if (t.IsValueType)
                    outputBlock.Text += " a value type\n";
                    outputBlock.Text += " a class\n";
            case TypeAttributes.Interface:
                outputBlock.Text += " an interface\n";

        if (0!=(attr & TypeAttributes.Abstract)) 
            outputBlock.Text += " abstract\n";

        if (0!=(attr & TypeAttributes.Sealed)) 
            outputBlock.Text += " sealed\n";

/* This example produces the following output:

Attributes for type Example: public AutoLayout a class abstract
Attributes for type NestedClass: nested and protected AutoLayout a class sealed
Attributes for type INested: nested and public AutoLayout an interface abstract
Attributes for type S: not public SequentialLayout a value type sealed


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

© 2017 Microsoft