Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
FindInterfaces Method
Collapse the table of content
Expand the table of content

Type.FindInterfaces Method

Returns an array of Type objects representing a filtered list of interfaces implemented or inherited by the current Type.

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

virtual array<Type^>^ FindInterfaces (
	TypeFilter^ filter, 
	Object^ filterCriteria
public Type[] FindInterfaces (
	TypeFilter filter, 
	Object filterCriteria
public function FindInterfaces (
	filter : TypeFilter, 
	filterCriteria : Object
) : Type[]



The TypeFilter delegate that compares the interfaces against filterCriteria.


The search criteria that determines whether an interface should be included in the returned array.

Return Value

An array of Type objects representing a filtered list of the interfaces implemented or inherited by the current Type, or an empty array of type Type if no interfaces matching the filter are implemented or inherited by the current Type.

Exception typeCondition


filter is a null reference (Nothing in Visual Basic).


A static initializer is invoked and throws an exception.

This method can be overridden by a derived class.

The Module.FilterTypeName and Module.FilterTypeNameIgnoreCase delegates supplied by the System.Reflection.Module class may also be used, in lieu of the System.Reflection.TypeFilter delegate.

All of the interfaces implemented by this class are considered during the search, whether declared by a base class or this class itself.

This method searches the base class hierarchy, returning each of the matching interfaces each class implements as well as all the matching interfaces each of those interfaces implements (that is, the transitive closure of the matching interfaces is returned). No duplicate interfaces are returned.

If the current Type represents a type parameter in the definition of a generic type or generic method, FindInterfaces searches all the interfaces declared in the constraints on the type parameter, and all interfaces inherited through the interfaces declared in the constraints. If the current Type represents a type argument of a generic type, FindInterfaces searches all the interfaces implemented by the type, whether or not they match constraints.


FindInterfaces can return generic interfaces, even on types that are not generic. For example, a nongeneric type might implement IEnumerable<int> (IEnumerable(Of Integer) in Visual Basic).

The following example finds the specified interface implemented or inherited by the specified type, and then displays the interface names.

#using <system.xml.dll>

using namespace System;
using namespace System::Xml;
using namespace System::Reflection;
public ref class MyFindInterfacesSample
    static bool MyInterfaceFilter(Type^ typeObj, Object^ criteriaObj)
            return true;
            return false;

int main()
        XmlDocument^ myXMLDoc = gcnew XmlDocument;
        myXMLDoc->LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" 
            + "<title>Pride And Prejudice</title> </book>");
        Type^ myType = myXMLDoc->GetType();
        // Specify the TypeFilter delegate that compares the interfaces 
        // against filter criteria.
        TypeFilter^ myFilter = gcnew TypeFilter( 
        array<String^>^myInterfaceList = {"System.Collections.IEnumerable",
        for(int index = 0; index < myInterfaceList->Length; index++)
            array<Type^>^myInterfaces = myType->FindInterfaces( 
                myFilter, myInterfaceList[index]);
            if(myInterfaces->Length > 0)
                Console::WriteLine("\n{0} implements the interface {1}.", 
                    myType, myInterfaceList[index]);
                for(int j = 0; j < myInterfaces->Length; j++)
                Console::WriteLine("Interfaces supported: {0}.",
                    "\n{0} does not implement the interface {1}.", 
                    myType, myInterfaceList[index]);

    catch(ArgumentNullException^ e) 
        Console::WriteLine("ArgumentNullException: {0}", e->Message);
    catch(TargetInvocationException^ e) 
        Console::WriteLine("TargetInvocationException: {0}", e->Message);
    catch(Exception^ e) 
        Console::WriteLine("Exception: {0}", e->Message);

import System.*;
import System.Xml.*;
import System.Reflection.*;

public class MyFindInterfacesSample
    public static void main(String[] args)
        try {
            XmlDocument myXmlDoc = new XmlDocument();
            myXmlDoc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>"
                + "<title>Pride And Prejudice</title>" + "</book>");
            Type myType = myXmlDoc.GetType();
            // Specify the TypeFilter delegate that compares the interfaces 
            // against filter criteria.
            TypeFilter myFilter = new TypeFilter(MyInterfaceFilter);
            String myInterfaceList[] = new String[] { 
                "System.Collections.ICollection" };
            for (int index = 0; index < myInterfaceList.length; index++) {
                Type myInterfaces[] = myType.FindInterfaces(myFilter,
                if (myInterfaces.length > 0) {
                    Console.WriteLine("\n{0} implements the interface {1}.",
                        myType, myInterfaceList.get_Item(index));
                    for (int j = 0; j < myInterfaces.length; j++) {
                        Console.WriteLine("Interfaces supported: {0}.",
                else {
                    Console.WriteLine("\n{0} does not implement the"
                        + " interface {1}.", myType,
        catch (ArgumentNullException e) {
            Console.WriteLine("ArgumentNullException: " + e.get_Message());
        catch (TargetInvocationException e) {
            Console.WriteLine("TargetInvocationException: " + e.get_Message());
        catch (System.Exception e) {
            Console.WriteLine("Exception: " + e.get_Message());
    } //main

    public static boolean MyInterfaceFilter(Type typeObj, Object criteriaObj)
        if (typeObj.ToString().Equals(criteriaObj.ToString())) {
            return true;
        else {
            return false;
    } //MyInterfaceFilter
} //MyFindInterfacesSample

Windows 98, Windows 2000 SP4, Windows Millennium Edition, 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

Community Additions

© 2015 Microsoft