System.Type.GetInterfaces 方法

方法描述

当在派生类中重写时,获取由当前 Type 实现或继承的所有接口。

语法定义(C# System.Type.GetInterfaces 方法 的用法)

public abstract Type[] GetInterfaces()

参数/返回值

参数值/返回值 参数类型/返回类型 参数描述/返回描述
返回值 System.Type[] 表示由当前 Type 实现或继承的所有接口的 Type 对象数组。 - 或 - 如果没有由当前 Type 实现或继承的接口,则为 Type 类型的空数组。

提示和注释

GetInterfaces 方法不按特定的顺序(如字母顺序或声明顺序)返回接口。 您的代码一定不能依赖于接口的返回顺序,因为该顺序可以改变。

如果当前 Type 表示构造泛型类型,则此方法将返回 Type 对象,并且其类型形参替换为相应的类型实参。

如果当前 Type 表示泛型类型或泛型方法的定义中的类型参数,则此方法搜索接口约束以及从类或接口约束继承的所有接口。

System.Type.GetInterfaces 方法例子

若要编译 Visual Basic 示例,请使用以下编译器命令:

using System;
using System.Collections.Generic;

public class Example
{
    static void Main()
    {
        Console.WriteLine("\r\nInterfaces implemented by Dictionary:\r\n");

        foreach (Type tinterface in typeof(Dictionary).GetInterfaces())
        {
            Console.WriteLine(tinterface.ToString());
        }

        //Console.ReadLine()      // Uncomment this line for Visual Studio. 
    }
}

/* This example produces output similar to the following:

Interfaces implemented by Dictionary:

System.Collections.Generic.IDictionary`2[System.Int32,System.String]
System.Collections.Generic.ICollection`1[System.Collections.Generic.KeyValuePair`2[System.Int32,System.String]]
System.Collections.Generic.IEnumerable`1[System.Collections.Generic.KeyValuePair`2[System.Int32,System.String]]
System.Collection.IEnumerable
System.Collection.IDictionary
System.Collection.ICollection
System.Runtime.Serialization.ISerializable
System.Runtime.Serialization.IDeserializationCallback
 */

异常

异常 异常描述
TargetInvocationException 调用静态初始值设定项并引发异常。

命名空间

namespace: System

程序集: mscorlib(在 mscorlib.dll 中)

版本信息

.NET Framework 受以下版本支持:4、3.5、3.0、2.0、1.1、1.0 .NET Framework Client Profile 受以下版本支持:4、3.5 SP1 受以下版本支持:

适用平台

Windows 7, Windows Vista SP1 或更高版本, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008(不支持服务器核心), Windows Server 2008 R2(支持 SP1 或更高版本的服务器核心), Windows Server 2003 SP2 .NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。