Type.GetInterfaces Method
When overridden in a derived class, gets all the interfaces implemented or inherited by the current Type.
[Visual Basic] Public MustOverride Function GetInterfaces() As Type() [C#] public abstract Type[] GetInterfaces(); [C++] public: virtual Type* GetInterfaces() [] = 0; [JScript] 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.
Exceptions
| Exception Type | Condition |
|---|---|
| TargetInvocationException | A static initializer is invoked and throws an exception. |
Example
[Visual Basic, C#, C++] 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:
[Visual Basic, C#, C++] vbc type_getinterfaces1.vb /r:System.Web.dll /r:System.dll
[Visual Basic] 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 [C#] 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); } } } } [C++] #using <mscorlib.dll> #using <system.dll> #using <system.web.dll> using namespace System; using namespace System::Web; using namespace System::Web::UI; public __gc class MyTemplate : public Control, public INamingContainer { private: String* _message; public: __property String* get_Message() { return _message; } __property void set_Message(String* value) { _message = value; } }; int main() { try { Type* myObjectArray[]= __typeof(MyTemplate)->GetInterfaces(); Console::WriteLine(S"The interfaces inherited by the MyTemplate class are:\n"); for (int index = 0; index < myObjectArray->Length; index++) { Console::WriteLine(myObjectArray->Item[index]); } } catch (Exception* e) { Console::WriteLine(S"An exception occurred."); Console::WriteLine(S"Message: {0}", e->Message); } }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard
See Also
Type Class | Type Members | System Namespace | GetInterface | FindInterfaces