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)

public abstract Type[] GetInterfaces ()
public abstract Type[] GetInterfaces ()
public abstract function GetInterfaces () : Type[]
Not applicable.

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.

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.

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


using System;
using System.Web;
using System.Web.UI;

namespace Samples
{
    public class MyTemplate : Control, INamingContainer 
    {
        private String _message = null;
        public String Message 
        {
            get 
            {
                return _message;
            }
            set 
            {
                _message = value;
            }
        }	
    }
    public class MyInterfacesSample
    {
        public static void Main()
        {
            try
            {
                Type[] myObjectArray= typeof(MyTemplate).GetInterfaces();
                Console.WriteLine("The interfaces inherited by the MyTemplate class are:\n");
                for (int index = 0; index < myObjectArray.Length; index++)
                {	
                    Console.WriteLine(myObjectArray[index]);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("An exception occurred.");
                Console.WriteLine("Message: " + e.Message);
            }
        }
    }
}


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 Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft