C# Type GetInterface(String, Boolean)

Description

Type GetInterface(String, Boolean) when overridden in a derived class, searches for the specified interface, specifying whether to do a case-insensitive search for the interface name.

Syntax

Type.GetInterface(String, Boolean) has the following syntax.


public abstract Type GetInterface(
  string name,
  bool ignoreCase
)

Parameters

Type.GetInterface(String, Boolean) has the following parameters.

  • name - The string containing the name of the interface to get. For generic interfaces, this is the mangled name.
  • ignoreCase - true to ignore the case of that part of name that specifies the simple interface name (the part that specifies the namespace must be correctly cased).
  • ignoreCase - -or-
  • ignoreCase - false to perform a case-sensitive search for all parts of name.

Returns

Type.GetInterface(String, Boolean) method returns An object representing the interface with the specified name, implemented or inherited by the current Type, if found; otherwise, null.

Example

The following code example uses the GetInterface(String, Boolean) method to perform a case-insensitive search of the Hashtable class for the IEnumerable interface.


using System.Collections;
using System;// w w w.  j a va  2  s.c o  m
using System.Reflection;
public class MainClass
{
    public static void Main(String[] argv)
    {
        Hashtable hashtableObj = new Hashtable();
        Type objType = hashtableObj.GetType();
        MethodInfo[] arrayMethodInfo;

        arrayMethodInfo = objType.GetInterface("IDeserializationCallback", false).GetMethods();
        for (int index = 0; index < arrayMethodInfo.Length; index++)
        {
            Console.WriteLine(arrayMethodInfo[index].ToString());
        }
    }
}

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