Type.GetInterface Metódus

Definíció

Lekéri az aktuális Typeáltal implementált vagy örökölt adott felületet.

Túlterhelések

Name Description
GetInterface(String)

Megkeresi a megadott névvel rendelkező felületet.

GetInterface(String, Boolean)

Ha egy származtatott osztályban felül van bírálva, megkeresi a megadott felületet, megadva, hogy kis- és nagybetűket nem érzéketlenül keres-e a felület nevére.

GetInterface(String)

Forrás:
Type.cs
Forrás:
Type.cs
Forrás:
Type.cs
Forrás:
Type.cs
Forrás:
Type.cs

Megkeresi a megadott névvel rendelkező felületet.

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

Paraméterek

name
String

A lekérni kívánt felület nevét tartalmazó sztring. Az általános felületek esetében ez a csonkolt név.

Válaszok

Az illesztőt a megadott névvel képviselő objektum, amelyet az aktuális Type( ha megtalálható) valósít meg vagy örököl, ellenkező esetben null.

Megvalósítás

Attribútumok

Kivételek

name az null.

Az aktuális Type típus egy olyan típust jelöl, amely ugyanazt az általános felületet implementálja különböző típusú argumentumokkal.

Példák

Az alábbi kódpéldában a metódus a GetInterface(String) felület osztályának Hashtable keresésére IDeserializationCallback szolgál, és felsorolja a felület metódusait.

A példakód a metódus túlterhelését GetInterface(String, Boolean) és a metódust GetInterfaceMap is bemutatja.

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

Megjegyzések

A keresés name érzékeli a kis- és nagybetűk közötti különbséget.

Ha a jelenlegi Type egy létrehozott általános típust jelöl, ez a metódus a Type-t adja vissza, ahol a típusparamétereket a megfelelő típusargumentumokkal helyettesítettük.

Ha az aktuális Type érték egy típusparamétert jelöl egy általános típus vagy általános metódus definíciójában, ez a metódus megkeresi az illesztőkorlátokat, valamint az osztály- vagy felületkorlátozásoktól örökölt interfészeket.

Note

Az általános interfészek esetében a name paraméter a keresztnév, amelynek végén egy sírjel (') és a típusparaméterek száma szerepel. Ez az általános felületdefiníciókra és a létrehozott általános felületekre is igaz. Ha például IExample<T> (IExample(Of T) Visual Basic) vagy IExample<string> (IExample(Of String) Visual Basic) kereséséhez keresse meg a "IExample`1".

Lásd még

A következőre érvényes:

GetInterface(String, Boolean)

Forrás:
Type.cs
Forrás:
Type.cs
Forrás:
Type.cs
Forrás:
Type.cs
Forrás:
Type.cs

Ha egy származtatott osztályban felül van bírálva, megkeresi a megadott felületet, megadva, hogy kis- és nagybetűket nem érzéketlenül keres-e a felület nevére.

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

Paraméterek

name
String

A lekérni kívánt felület nevét tartalmazó sztring. Az általános felületek esetében ez a csonkolt név.

ignoreCase
Boolean

true ha figyelmen kívül szeretné hagyni annak a résznek az esetét name , amely az egyszerű felületnevet adja meg (a névteret meghatározó részt helyesen kell kisbetűvel megadni).

-vagy-

false a minden részén namekis- és nagybetűket megkülönböztető keresést hajthat végre.

Válaszok

Az illesztőt a megadott névvel képviselő objektum, amelyet az aktuális Type( ha megtalálható) valósít meg vagy örököl, ellenkező esetben null.

Megvalósítás

Attribútumok

Kivételek

name az null.

Az aktuális Type típus egy olyan típust jelöl, amely ugyanazt az általános felületet implementálja különböző típusú argumentumokkal.

Példák

Az alábbi kódpéldában a GetInterface(String, Boolean) metódussal kis- és nagybetűket nem érzékelyítő keresést hajthat végre a HashtableIEnumerable felület osztályában.

A példakód a metódus túlterhelését GetInterface(String) és a metódust GetInterfaceMap is bemutatja.

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

Megjegyzések

A ignoreCase paraméter csak az egyszerű felület nevére vonatkozik, a névtérre nem. A névteret meghatározó résznek name helyes esettel kell rendelkeznie, vagy a felület nem található. A "System.icomparable" sztring például megkeresi a IComparable felületet, de a "system.icomparable" sztring nem.

Ha a jelenlegi Type egy létrehozott általános típust jelöl, ez a metódus a Type-t adja vissza, ahol a típusparamétereket a megfelelő típusargumentumokkal helyettesítettük.

Ha az aktuális Type érték egy típusparamétert jelöl egy általános típus vagy általános metódus definíciójában, ez a metódus megkeresi az illesztőkorlátokat, valamint az osztály- vagy felületkorlátozásoktól örökölt interfészeket.

Note

Az általános interfészek esetében a name paraméter a keresztnév, amelynek végén egy sírjel (') és a típusparaméterek száma szerepel. Ez az általános felületdefiníciókra és a létrehozott általános felületekre is igaz. Ha például IExample<T> (IExample(Of T) Visual Basic) vagy IExample<string> (IExample(Of String) Visual Basic) kereséséhez keresse meg a "IExample`1".

Lásd még

A következőre érvényes: