Share via


Type.Attributes 属性

获取与 Type 关联的属性。

**命名空间:**System
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
Public ReadOnly Property Attributes As TypeAttributes
用法
Dim instance As Type
Dim value As TypeAttributes

value = instance.Attributes
public TypeAttributes Attributes { get; }
public:
virtual property TypeAttributes Attributes {
    TypeAttributes get () sealed;
}
/** @property */
public final TypeAttributes get_Attributes ()
public final function get Attributes () : TypeAttributes

属性值

表示 Type 的属性集的 TypeAttributes 对象,除非 Type 表示泛型类型形参,在此情况下该值未指定。

备注

如果当前 Type 表示构造泛型类型,则此属性将返回泛型类型定义的属性 (Property)。例如,为 MyGenericClass<int>(在 Visual Basic 中为MyGenericClass(Of Integer))返回的属性是 MyGenericClass<T>(在 Visual Basic 中为 MyGenericClass(Of T))的属性。

如果当前 Type 表示泛型类型形参 — 也就是说,如果 IsGenericParameter 属性 (Property) 返回 true — 则此属性 (Property) 返回的 TypeAttributes 值未指定。

示例

下面的示例说明 Type.Attributes 属性 (Property) 的用法。

Imports System
Imports System.Reflection

Public Class Class1
    Protected t As Type
    Public Sub Method1()
        If t.Attributes And TypeAttributes.ClassSemanticsMask = TypeAttributes.Interface Then
            Console.WriteLine("t is an interface.")
        End If
        If t.Attributes And TypeAttributes.Public <> 0 Then
            Console.WriteLine("t is public.")
        End If
    End Sub 'Method1
End Class 'Class1
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.");
    }
}
#using <System.DLL>

using namespace System;
using namespace System::Reflection;
ref class Sample
{
private:
   void Method( Type^ t )
   {
      if ( (t->Attributes & TypeAttributes::ClassSemanticsMask) == TypeAttributes::Interface )
            Console::WriteLine(  "t is an interface." );

      if ( (t->Attributes & TypeAttributes::Public) != (TypeAttributes)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

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

Type 类
Type 成员
System 命名空间
GetAttributeFlagsImpl
TypeAttributes