Udostępnij za pośrednictwem


Type.GetInterface Metoda

Definicja

Pobiera określony interfejs zaimplementowany lub dziedziczony przez bieżący Typeelement .

Przeciążenia

Nazwa Opis
GetInterface(String, Boolean)

Po zastąpieniu w klasie pochodnej wyszukuje określony interfejs, określając, czy należy wykonać wyszukiwanie bez uwzględniania wielkości liter dla nazwy interfejsu.

GetInterface(String)

Wyszukuje interfejs o określonej nazwie.

GetInterface(String, Boolean)

Źródło:
Type.cs
Źródło:
Type.cs
Źródło:
Type.cs
Źródło:
Type.cs
Źródło:
Type.cs

Po zastąpieniu w klasie pochodnej wyszukuje określony interfejs, określając, czy należy wykonać wyszukiwanie bez uwzględniania wielkości liter dla nazwy interfejsu.

public:
 abstract Type ^ GetInterface(System::String ^ name, bool ignoreCase);
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.Interfaces)]
public abstract Type? GetInterface(string name, bool ignoreCase);
public abstract Type? GetInterface(string name, bool ignoreCase);
public abstract Type GetInterface(string name, bool ignoreCase);
[<System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.Interfaces)>]
abstract member GetInterface : string * bool -> Type
abstract member GetInterface : string * bool -> Type
Public MustOverride Function GetInterface (name As String, ignoreCase As Boolean) As Type

Parametry

name
String

Ciąg zawierający nazwę interfejsu do pobrania. W przypadku interfejsów ogólnych jest to nazwa mangled.

ignoreCase
Boolean

true aby zignorować przypadek tej name części, która określa prostą nazwę interfejsu (część określająca przestrzeń nazw musi być poprawnie przypadek).

— lub —

false w celu przeprowadzenia wyszukiwania uwzględniającego wielkość liter dla wszystkich części elementu name.

Zwraca

Obiekt reprezentujący interfejs o określonej nazwie, zaimplementowany lub odziedziczony przez bieżący Typeelement , jeśli zostanie znaleziony; w przeciwnym razie null.

Implementuje

Atrybuty

Wyjątki

Parametr name ma wartość null.

Bieżący Type reprezentuje typ, który implementuje ten sam interfejs ogólny z różnymi argumentami typu.

Przykłady

Poniższy przykład kodu używa GetInterface(String, Boolean) metody do przeprowadzania wyszukiwania Hashtable bez uwzględniania wielkości liter dla klasy dla interfejsu IEnumerable .

W przykładzie kodu przedstawiono GetInterface(String) również przeciążenie metody i metodę GetInterfaceMap .

public static void Main()
{
    Hashtable hashtableObj = new Hashtable();
    Type objType = hashtableObj.GetType();
    MethodInfo[] arrayMethodInfo;
    MemberInfo[] arrayMemberInfo;
    try
    {
        // Get the methods implemented in 'IDeserializationCallback' interface.
        arrayMethodInfo =objType.GetInterface("IDeserializationCallback").GetMethods();
        Console.WriteLine ("\nMethods of 'IDeserializationCallback' Interface :");
        foreach(MethodInfo methodInfo in arrayMethodInfo)
            Console.WriteLine (methodInfo);

        // Get FullName for interface by using Ignore case search.
        Console.WriteLine ("\nMethods of 'IEnumerable' Interface");
        arrayMethodInfo = objType.GetInterface("ienumerable",true).GetMethods();
        foreach(MethodInfo methodInfo in arrayMethodInfo)
           Console.WriteLine (methodInfo);

        //Get the Interface methods for 'IDictionary' interface
        InterfaceMapping interfaceMappingOb = objType.GetInterfaceMap(typeof(IDictionary));
        arrayMemberInfo = interfaceMappingObj.InterfaceMethods;
        Console.WriteLine ("\nHashtable class Implements the following IDictionary Interface methods :");
        foreach(MemberInfo memberInfo in arrayMemberInfo)
           Console.WriteLine (memberInfo);
    }
    catch (Exception e)
    {
        Console.WriteLine ("Exception : " + e.ToString());
    }
}
let hashtableObj = Hashtable()
let objType = hashtableObj.GetType()
try
    // Get the methods implemented in 'IDeserializationCallback' interface.
    let arrayMethodInfo = objType.GetInterface("IDeserializationCallback").GetMethods()
    printfn "\nMethods of 'IDeserializationCallback' Interface :"
    for methodInfo in arrayMethodInfo do
        printfn $"{methodInfo}"

    // Get FullName for interface by using Ignore case search.
    printfn "\nMethods of 'IEnumerable' Interface"
    let arrayMethodInfo = objType.GetInterface("ienumerable",true).GetMethods()
    for methodInfo in arrayMethodInfo do
        printfn $"{methodInfo}"

    //Get the Interface methods for 'IDictionary' interface
    let interfaceMappingObj = objType.GetInterfaceMap typeof<IDictionary>
    let arrayMemberInfo = interfaceMappingObj.InterfaceMethods
    printfn "\nHashtable class Implements the following IDictionary Interface methods :"
    for memberInfo in arrayMemberInfo do
        printfn $"{memberInfo}"
with e ->
    printfn $"Exception : {e}"
   Public Shared Sub Main()
      Dim hashtableObj As New Hashtable()
      Dim objType As Type = hashtableObj.GetType()
      Dim arrayMemberInfo() As MemberInfo
      Dim arrayMethodInfo() As MethodInfo
      Try
         ' Get the methods implemented in 'IDeserializationCallback' interface.
         arrayMethodInfo = objType.GetInterface("IDeserializationCallback").GetMethods()
         Console.WriteLine(ControlChars.Cr + "Methods of 'IDeserializationCallback' Interface :")
         Dim index As Integer
         For index = 0 To arrayMethodInfo.Length - 1
            Console.WriteLine(arrayMethodInfo(index).ToString())
         Next index
         ' Get FullName for interface by using Ignore case search.
         Console.WriteLine(ControlChars.Cr + "Methods of 'IEnumerable' Interface")
         arrayMethodInfo = objType.GetInterface("ienumerable", True).GetMethods()
         For index = 0 To arrayMethodInfo.Length - 1
            Console.WriteLine(arrayMethodInfo(index).ToString())
         Next index
         'Get the Interface methods for 'IDictionary' interface
         Dim interfaceMappingObj As InterfaceMapping
         interfaceMappingObj = objType.GetInterfaceMap(GetType(IDictionary))
         arrayMemberInfo = interfaceMappingObj.InterfaceMethods
         Console.WriteLine(ControlChars.Cr + "Hashtable class Implements the following IDictionary Interface methods :")
         For index = 0 To arrayMemberInfo.Length - 1
            Console.WriteLine(arrayMemberInfo(index).ToString())
         Next index
      Catch e As Exception
         Console.WriteLine(("Exception : " + e.ToString()))
      End Try
   End Sub
End Class

Uwagi

Parametr ignoreCase ma zastosowanie tylko do prostej nazwy interfejsu, a nie do przestrzeni nazw. Część name określająca przestrzeń nazw musi mieć prawidłowy przypadek lub interfejs nie zostanie znaleziony. Na przykład ciąg "System.icomparable" znajduje IComparable interfejs, ale ciąg "system.icomparable" nie.

Jeśli bieżący Type reprezentuje skonstruowany typ ogólny, ta metoda zwraca Type z zastąpionymi parametrami typu przez odpowiednie argumenty typu.

Jeśli bieżący Type reprezentuje parametr typu w definicji typu ogólnego lub metody ogólnej, ta metoda wyszukuje ograniczenia interfejsu i wszelkie interfejsy dziedziczone z ograniczeń klasy lub interfejsu.

Uwaga / Notatka

W przypadku interfejsów name ogólnych parametr jest nazwą mangled, kończącą się akcentem grobowym (') i liczbą parametrów typu. Dotyczy to zarówno ogólnych definicji interfejsu, jak i skonstruowanych interfejsów ogólnych. Aby na przykład znaleźć IExample<T> (IExample(Of T) w Visual Basic) lub IExample<string> (IExample(Of String) w Visual Basic), wyszukaj "IExample`1".

Zobacz też

Dotyczy

GetInterface(String)

Źródło:
Type.cs
Źródło:
Type.cs
Źródło:
Type.cs
Źródło:
Type.cs
Źródło:
Type.cs

Wyszukuje interfejs o określonej nazwie.

public:
 Type ^ GetInterface(System::String ^ name);
public:
 virtual Type ^ GetInterface(System::String ^ name);
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.Interfaces)]
public Type? GetInterface(string name);
public Type? GetInterface(string name);
public Type GetInterface(string name);
[<System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.Interfaces)>]
member this.GetInterface : string -> Type
member this.GetInterface : string -> Type
abstract member GetInterface : string -> Type
override this.GetInterface : string -> Type
Public Function GetInterface (name As String) As Type

Parametry

name
String

Ciąg zawierający nazwę interfejsu do pobrania. W przypadku interfejsów ogólnych jest to nazwa mangled.

Zwraca

Obiekt reprezentujący interfejs o określonej nazwie, zaimplementowany lub odziedziczony przez bieżący Typeelement , jeśli zostanie znaleziony; w przeciwnym razie null.

Implementuje

Atrybuty

Wyjątki

Parametr name ma wartość null.

Bieżący Type reprezentuje typ, który implementuje ten sam interfejs ogólny z różnymi argumentami typu.

Przykłady

Poniższy przykład kodu używa GetInterface(String) metody do wyszukiwania Hashtable klasy dla interfejsu IDeserializationCallback i wyświetla listę metod interfejsu.

W przykładzie kodu przedstawiono GetInterface(String, Boolean) również przeciążenie metody i metodę GetInterfaceMap .

public static void Main()
{
    Hashtable hashtableObj = new Hashtable();
    Type objType = hashtableObj.GetType();
    MethodInfo[] arrayMethodInfo;
    MemberInfo[] arrayMemberInfo;
    try
    {
        // Get the methods implemented in 'IDeserializationCallback' interface.
        arrayMethodInfo =objType.GetInterface("IDeserializationCallback").GetMethods();
        Console.WriteLine ("\nMethods of 'IDeserializationCallback' Interface :");
        foreach(MethodInfo methodInfo in arrayMethodInfo)
            Console.WriteLine (methodInfo);

        // Get FullName for interface by using Ignore case search.
        Console.WriteLine ("\nMethods of 'IEnumerable' Interface");
        arrayMethodInfo = objType.GetInterface("ienumerable",true).GetMethods();
        foreach(MethodInfo methodInfo in arrayMethodInfo)
           Console.WriteLine (methodInfo);

        //Get the Interface methods for 'IDictionary' interface
        InterfaceMapping interfaceMappingOb = objType.GetInterfaceMap(typeof(IDictionary));
        arrayMemberInfo = interfaceMappingObj.InterfaceMethods;
        Console.WriteLine ("\nHashtable class Implements the following IDictionary Interface methods :");
        foreach(MemberInfo memberInfo in arrayMemberInfo)
           Console.WriteLine (memberInfo);
    }
    catch (Exception e)
    {
        Console.WriteLine ("Exception : " + e.ToString());
    }
}
let hashtableObj = Hashtable()
let objType = hashtableObj.GetType()
try
    // Get the methods implemented in 'IDeserializationCallback' interface.
    let arrayMethodInfo = objType.GetInterface("IDeserializationCallback").GetMethods()
    printfn "\nMethods of 'IDeserializationCallback' Interface :"
    for methodInfo in arrayMethodInfo do
        printfn $"{methodInfo}"

    // Get FullName for interface by using Ignore case search.
    printfn "\nMethods of 'IEnumerable' Interface"
    let arrayMethodInfo = objType.GetInterface("ienumerable",true).GetMethods()
    for methodInfo in arrayMethodInfo do
        printfn $"{methodInfo}"

    //Get the Interface methods for 'IDictionary' interface
    let interfaceMappingObj = objType.GetInterfaceMap typeof<IDictionary>
    let arrayMemberInfo = interfaceMappingObj.InterfaceMethods
    printfn "\nHashtable class Implements the following IDictionary Interface methods :"
    for memberInfo in arrayMemberInfo do
        printfn $"{memberInfo}"
with e ->
    printfn $"Exception : {e}"
   Public Shared Sub Main()
      Dim hashtableObj As New Hashtable()
      Dim objType As Type = hashtableObj.GetType()
      Dim arrayMemberInfo() As MemberInfo
      Dim arrayMethodInfo() As MethodInfo
      Try
         ' Get the methods implemented in 'IDeserializationCallback' interface.
         arrayMethodInfo = objType.GetInterface("IDeserializationCallback").GetMethods()
         Console.WriteLine(ControlChars.Cr + "Methods of 'IDeserializationCallback' Interface :")
         Dim index As Integer
         For index = 0 To arrayMethodInfo.Length - 1
            Console.WriteLine(arrayMethodInfo(index).ToString())
         Next index
         ' Get FullName for interface by using Ignore case search.
         Console.WriteLine(ControlChars.Cr + "Methods of 'IEnumerable' Interface")
         arrayMethodInfo = objType.GetInterface("ienumerable", True).GetMethods()
         For index = 0 To arrayMethodInfo.Length - 1
            Console.WriteLine(arrayMethodInfo(index).ToString())
         Next index
         'Get the Interface methods for 'IDictionary' interface
         Dim interfaceMappingObj As InterfaceMapping
         interfaceMappingObj = objType.GetInterfaceMap(GetType(IDictionary))
         arrayMemberInfo = interfaceMappingObj.InterfaceMethods
         Console.WriteLine(ControlChars.Cr + "Hashtable class Implements the following IDictionary Interface methods :")
         For index = 0 To arrayMemberInfo.Length - 1
            Console.WriteLine(arrayMemberInfo(index).ToString())
         Next index
      Catch e As Exception
         Console.WriteLine(("Exception : " + e.ToString()))
      End Try
   End Sub
End Class

Uwagi

Wyszukiwanie name uwzględnia wielkość liter.

Jeśli bieżący Type reprezentuje skonstruowany typ ogólny, ta metoda zwraca Type z zastąpionymi parametrami typu przez odpowiednie argumenty typu.

Jeśli bieżący Type reprezentuje parametr typu w definicji typu ogólnego lub metody ogólnej, ta metoda wyszukuje ograniczenia interfejsu i wszelkie interfejsy dziedziczone z ograniczeń klasy lub interfejsu.

Uwaga / Notatka

W przypadku interfejsów name ogólnych parametr jest nazwą mangled, kończącą się akcentem grobowym (') i liczbą parametrów typu. Dotyczy to zarówno ogólnych definicji interfejsu, jak i skonstruowanych interfejsów ogólnych. Aby na przykład znaleźć IExample<T> (IExample(Of T) w Visual Basic) lub IExample<string> (IExample(Of String) w Visual Basic), wyszukaj "IExample`1".

Zobacz też

Dotyczy