Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

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

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 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.