This documentation is archived and is not being maintained.

Type.Attributes Property

Gets the attributes associated with the Type.

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

public TypeAttributes Attributes { get; }
/** @property */
public final TypeAttributes get_Attributes ()

public final function get Attributes () : TypeAttributes

Not applicable.

Property Value

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.

using System;
using System.Reflection;

public class Class1 
{
    protected Type t;
    public void Method1() 
    {
        if ((t.Attributes & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface)
            Console.WriteLine ("t is an interface.");
        if ((t.Attributes & TypeAttributes.Public) != 0)
            Console.WriteLine ("t is public.");
    }
}

import System.*;
import System.Reflection.*;

public class Class1
{
    protected Type t;    
    public void Method1()
    {
        if ((t.get_Attributes() & TypeAttributes.ClassSemanticsMask)
            == TypeAttributes.Interface  ) {
                Console.WriteLine("t is an interface.");
        }
        if (((int)(t.get_Attributes() & TypeAttributes.Public)) != 0  ) {
            Console.WriteLine("t is public.");
        }
    } //Method1
} //Class1

if ((t.Attributes & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface)
    Console.WriteLine ("t is an Interface");
if ((t.Attributes & TypeAttributes.Public) != 0)
    Console.WriteLine ("t is public");

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, 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

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0
Show: