Type.GetInterface Metoda

Definicja

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

Przeciążenia

GetInterface(String)

Wyszukuje interfejs o określonej nazwie.

GetInterface(String, Boolean)

Po przesłonięciu w klasie pochodnej wyszukuje określony interfejs, określając, czy należy wyszukać nazwę interfejsu bez uwzględniania wielkości liter.

GetInterface(String)

Ź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);
public Type? GetInterface (string name);
public Type GetInterface (string name);
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 dziedziczony przez bieżący Typeobiekt , jeśli zostanie znaleziony; w przeciwnym razie null.

Implementuje

Wyjątki

name to 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 zawiera listę metod interfejsu.

Przykładowy kod pokazuje GetInterface(String, Boolean) również przeciążenie metody i metodę GetInterfaceMap .

int main()
{
   Hashtable^ hashtableObj = gcnew Hashtable;
   Type^ objType = hashtableObj->GetType();
   array<MemberInfo^>^arrayMemberInfo;
   array<MethodInfo^>^arrayMethodInfo;
   try
   {
      // Get the methods implemented in 'IDeserializationCallback' interface.
      arrayMethodInfo = objType->GetInterface( "IDeserializationCallback" )->GetMethods();
      Console::WriteLine( "\nMethods of 'IDeserializationCallback' Interface :" );
      for ( int index = 0; index < arrayMethodInfo->Length; index++ )
         Console::WriteLine( arrayMethodInfo[ index ] );
      
      // Get FullName for interface by using Ignore case search.
      Console::WriteLine( "\nMethods of 'IEnumerable' Interface" );
      arrayMethodInfo = objType->GetInterface( "ienumerable", true )->GetMethods();
      for ( int index = 0; index < arrayMethodInfo->Length; index++ )
         Console::WriteLine( arrayMethodInfo[ index ] );
      
      //Get the Interface methods for 'IDictionary*' interface
      InterfaceMapping interfaceMappingObj;
      interfaceMappingObj = objType->GetInterfaceMap( IDictionary::typeid );
      arrayMemberInfo = interfaceMappingObj.InterfaceMethods;
      Console::WriteLine( "\nHashtable class Implements the following IDictionary Interface methods :" );
      for ( int index = 0; index < arrayMemberInfo->Length; index++ )
         Console::WriteLine( arrayMemberInfo[ index ] );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "Exception : {0}", e );
   }
}
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 jest uwzględniane w wielkości liter.

Jeśli bieżący Type reprezentuje skonstruowany typ ogólny, ta metoda zwraca Type parametry typu zastąpione 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

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 ciąg "IExample`1".

Zobacz też

Dotyczy

GetInterface(String, Boolean)

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

Po przesłonięciu w klasie pochodnej wyszukuje określony interfejs, określając, czy należy wyszukać nazwę interfejsu bez uwzględniania wielkości liter.

public:
 abstract Type ^ GetInterface(System::String ^ name, bool ignoreCase);
public abstract Type? GetInterface (string name, bool ignoreCase);
public abstract Type GetInterface (string name, bool ignoreCase);
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 aby wykonać wyszukiwanie w przypadku dla wszystkich części obiektu name.

Zwraca

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

Implementuje

Wyjątki

name to 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 niewrażliwego na wielkość liter wyszukiwania Hashtable klasy dla interfejsu IEnumerable .

Przykładowy kod pokazuje GetInterface(String) również przeciążenie metody i metodę GetInterfaceMap .

int main()
{
   Hashtable^ hashtableObj = gcnew Hashtable;
   Type^ objType = hashtableObj->GetType();
   array<MemberInfo^>^arrayMemberInfo;
   array<MethodInfo^>^arrayMethodInfo;
   try
   {
      // Get the methods implemented in 'IDeserializationCallback' interface.
      arrayMethodInfo = objType->GetInterface( "IDeserializationCallback" )->GetMethods();
      Console::WriteLine( "\nMethods of 'IDeserializationCallback' Interface :" );
      for ( int index = 0; index < arrayMethodInfo->Length; index++ )
         Console::WriteLine( arrayMethodInfo[ index ] );
      
      // Get FullName for interface by using Ignore case search.
      Console::WriteLine( "\nMethods of 'IEnumerable' Interface" );
      arrayMethodInfo = objType->GetInterface( "ienumerable", true )->GetMethods();
      for ( int index = 0; index < arrayMethodInfo->Length; index++ )
         Console::WriteLine( arrayMethodInfo[ index ] );
      
      //Get the Interface methods for 'IDictionary*' interface
      InterfaceMapping interfaceMappingObj;
      interfaceMappingObj = objType->GetInterfaceMap( IDictionary::typeid );
      arrayMemberInfo = interfaceMappingObj.InterfaceMethods;
      Console::WriteLine( "\nHashtable class Implements the following IDictionary Interface methods :" );
      for ( int index = 0; index < arrayMemberInfo->Length; index++ )
         Console::WriteLine( arrayMemberInfo[ index ] );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "Exception : {0}", e );
   }
}
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 dotyczy tylko prostej nazwy interfejsu, a nie przestrzeni nazw. Część określająca name 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 parametry typu zastąpione 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

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 ciąg "IExample`1".

Zobacz też

Dotyczy