C# TypeInfo FindInterfaces

Description

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

Syntax

TypeInfo.FindInterfaces has the following syntax.


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

Parameters

TypeInfo.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

TypeInfo.FindInterfaces method returns

Example


using System;/*from  w  ww . ja  v  a  2 s.  com*/
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);
            String[] myInterfaceList = new String[] {"System.Collections.ICollection"};
            for(int index=0; index < myInterfaceList.Length; index++)
            {
                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}.", 
                            myInterfaces[j].ToString());
                }
            }
    }

    public static bool MyInterfaceFilter(Type typeObj,Object criteriaObj)
    {
        if(typeObj.ToString() == criteriaObj.ToString())
            return true;
        else 
            return false;
    }
}




















Home »
  C# Tutorial »
    System.Reflection »




EventInfo
FieldInfo
MemberInfo
MethodInfo
ParameterInfo
TypeInfo