共用方式為


Type.GetInterfaces Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

When overridden in a derived class, gets all the interfaces implemented or inherited by the current Type.

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

Syntax

'Declaration
Public MustOverride Function GetInterfaces As Type()
public abstract Type[] GetInterfaces()

Return Value

Type: array<System.Type[]
An array of Type objects representing all the interfaces implemented or inherited by the current Type.
-or-
An empty array of type Type, if no interfaces are implemented or inherited by the current Type.

Exceptions

Exception Condition
TargetInvocationException

A static initializer is invoked and throws an exception.

Remarks

The GetInterfaces method does not return interfaces in a particular order, such as alphabetical or declaration order. Your code must not depend on the order in which interfaces are returned, because that order varies.

If the current Type represents a constructed generic type, this method returns the Type objects with the type parameters replaced by the appropriate type arguments.

If the current Type represents a type parameter in the definition of a generic type or generic method, this method searches the interface constraints and any interfaces inherited from class or interface constraints.

Examples

The following example gets the type of the specified class and displays all the interfaces that the type implements or inherits.

Imports System.Collections.Generic

Public Class Example

    Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)

        outputBlock.Text &= _
            "Interfaces implemented by Dictionary(Of Integer, String):" & vbLf
        For Each ti As Type In GetType(Dictionary(Of Integer, String)).GetInterfaces()

            outputBlock.Text &= ti.ToString() & vbLf

        Next 
    End Sub
End Class

' This example produces output similar to the following:
'
'Interfaces implemented by Dictionary(Of Integer, String):
'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

using System;
using System.Collections.Generic;

public class Example
{
    public static void Demo(System.Windows.Controls.TextBlock outputBlock)
    {
        outputBlock.Text += 
            "Interfaces implemented by Dictionary<int, string>:\n";
        foreach (Type ti in typeof(Dictionary<int, string>).GetInterfaces())
        {
            outputBlock.Text += ti.ToString() + "\n";
        }
    }
}

/* This example produces output similar to the following:

Interfaces implemented by Dictionary<int, string>:
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
 */

Version Information

Silverlight

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

Platforms

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