Export (0) Print
Expand All
Expand Minimize

Type.GetInterfaces Method

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

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

'Declaration
Public MustOverride Function GetInterfaces As Type()
'Usage
Dim instance As Type
Dim returnValue As Type()

returnValue = instance.GetInterfaces
public abstract Type[] GetInterfaces ()
public abstract function GetInterfaces () : Type[]

Return Value

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.

Exception typeCondition

TargetInvocationException

A static initializer is invoked and throws an exception.

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.

The following example gets the type of the specified class and displays all the interfaces that the type implements or inherits. To compile the Visual Basic example, use the following compiler commands:

vbc type_getinterfaces1.vb /r:System.Web.dll /r:System.dll


Imports System
Imports System.Web
Imports System.Web.UI
Imports Microsoft.VisualBasic

Namespace Samples
    Public Class MyTemplate
        Inherits Control
        Implements INamingContainer
        Private _message As [String] = Nothing
        Public Property Message() As [String]
            Get
                Return _message
            End Get
            Set(ByVal Value As [String])
                _message = value
            End Set
        End Property
    End Class
    Public Class MyInterfacesSample
        Public Shared Sub Main()
            Try
                Dim myObjectArray As Type() = GetType(MyTemplate).GetInterfaces()
                Console.WriteLine("The interfaces inherited by the MyTemplate class are:" + ControlChars.CrLf)
                Dim index As Integer
                For index = 0 To myObjectArray.Length - 1
                    Console.WriteLine(myObjectArray(index))
                Next index
            Catch e As Exception
                Console.WriteLine("An exception occurred.")
                Console.WriteLine("Message: {0}", e.Message)
            End Try
        End Sub
    End Class
End Namespace


package Samples;

import System.*;
import System.Web.*;
import System.Web.UI.*;

public class MyTemplate extends Control implements INamingContainer
{
    private String _message = null;

    /** @property 
     */
    public String get_Message()
    {
        return _message;
    } //get_Message

    /** @property 
     */
    public void set_Message(String value)
    {
        _message = value;
    } //set_Message
} //MyTemplate

public class MyInterfacesSample
{
    public static void main(String[] args)
    {
        try {
            Type myObjectArray[] = MyTemplate.class.ToType().GetInterfaces();
            Console.WriteLine("The interfaces inherited by the MyTemplate"
                + " class are:\n");
            for (int index = 0; index < myObjectArray.length; index++) {
                Console.WriteLine(myObjectArray.get_Item(index));
            }
        }
        catch (System.Exception e) {
            Console.WriteLine("An exception occurred.");
            Console.WriteLine("Message: " + e.get_Message());
        }
    } //main
} //MyInterfacesSample

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

Community Additions

ADD
Show:
© 2014 Microsoft