C# Type FindInterfaces

Description

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

Syntax

Type.FindInterfaces has the following syntax.


public virtual Type[] FindInterfaces(
  TypeFilter filter,
  Object filterCriteria
)

Parameters

Type.FindInterfaces has the following parameters.

  • filter - The delegate that compares the interfaces against filterCriteria.
  • filterCriteria - The search criteria that determines whether an interface should be included in the returned array.

Returns

Type.FindInterfaces method returns

Example

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


using System;/*w  ww.ja  va 2 s .  co m*/
using System.Xml;
using System.Reflection;

public class MyFindInterfacesSample 
{
    public static void Main()
    {
            XmlDocument myXMLDoc = new XmlDocument();
            Type myType = myXMLDoc.GetType();

            TypeFilter myFilter = new TypeFilter(MyInterfaceFilter);
            Type[] myInterfaces = myType.FindInterfaces(myFilter, 
                    "System.Collections.IEnumerable");
    }
    public static bool MyInterfaceFilter(Type typeObj,Object criteriaObj)
    {
        if(typeObj.ToString() == criteriaObj.ToString())
            return true;
        else 
            return false;
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version