Type.GetInterfaces Metódus
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Ha felül van bírálva egy származtatott osztályban, lekéri az aktuális Typeáltal implementált vagy örökölt összes felületet.
public:
abstract cli::array <Type ^> ^ GetInterfaces();
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.Interfaces)]
public abstract Type[] GetInterfaces();
public abstract Type[] GetInterfaces();
[<System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.Interfaces)>]
abstract member GetInterfaces : unit -> Type[]
abstract member GetInterfaces : unit -> Type[]
Public MustOverride Function GetInterfaces () As Type()
Válaszok
Az aktuálisan Typeimplementált vagy örökölt összes illesztőt képviselő objektumtömbType.
-vagy-
Üres típusú Typetömb, ha az aktuális nem valósítja meg vagy örökli az illesztőket Type.
Megvalósítás
- Attribútumok
Kivételek
A rendszer meghív egy statikus inicializálót, és kivételt jelez.
Példák
Az alábbi példa lekéri a megadott osztály típusát, és megjeleníti az összes felületet, amelyet a típus implementál vagy örököl. A Visual Basic példa fordításához használja a következő fordítóparancsokat:
vbc type_getinterfaces1.vb /r:System.Web.dll /r:System.dll
using System;
using System.Collections.Generic;
public class Example
{
static void Main()
{
Console.WriteLine("\r\nInterfaces implemented by Dictionary<int, string>:\r\n");
foreach (Type tinterface in typeof(Dictionary<int, string>).GetInterfaces())
{
Console.WriteLine(tinterface.ToString());
}
//Console.ReadLine() // Uncomment this line for Visual Studio.
}
}
/* This example produces output similar to the following:
Interfaces implemented by Dictionary<int, string>:
System.Collections.Generic.IDictionary`2[System.Int32,System.String]
System.Collections.Generic.ICollection`1[System.Collections.Generic.KeyValuePair`2[System.Int32,System.String]]
System.Collections.Generic.IEnumerable`1[System.Collections.Generic.KeyValuePair`2[System.Int32,System.String]]
System.Collection.IEnumerable
System.Collection.IDictionary
System.Collection.ICollection
System.Runtime.Serialization.ISerializable
System.Runtime.Serialization.IDeserializationCallback
*/
open System.Collections.Generic
printfn "\nInterfaces implemented by Dictionary<int, string>:\n"
for tinterface in typeof<Dictionary<int, string>>.GetInterfaces() do
printfn $"{tinterface}"
(* This example produces output similar to the following:
Interfaces implemented by Dictionary<int, string>:
System.Collections.Generic.IDictionary`2[System.Int32,System.String]
System.Collections.Generic.ICollection`1[System.Collections.Generic.KeyValuePair`2[System.Int32,System.String]]
System.Collections.Generic.IEnumerable`1[System.Collections.Generic.KeyValuePair`2[System.Int32,System.String]]
System.Collection.IEnumerable
System.Collection.IDictionary
System.Collection.ICollection
System.Runtime.Serialization.ISerializable
System.Runtime.Serialization.IDeserializationCallback
*)
Imports System.Collections.Generic
Public Class Example
Shared Sub Main()
Console.WriteLine(vbCrLf & _
"Interfaces implemented by Dictionary(Of Integer, String):" & vbCrLf)
For Each tinterface As Type In GetType(Dictionary(Of Integer, String)).GetInterfaces()
Console.WriteLine(tinterface.ToString())
Next
'Console.ReadLine() ' Uncomment this line for Visual Studio.
End Sub
End Class
' This example produces output similar to the following:
'
'Interfaces implemented by Dictionary(Of Integer, String):
'System.Collections.Generic.IDictionary`2[System.Int32,System.String]
'System.Collections.Generic.ICollection`1[System.Collections.Generic.KeyValuePair`2[System.Int32,System.String]]
'System.Collections.Generic.IEnumerable`1[System.Collections.Generic.KeyValuePair`2[System.Int32,System.String]]
'System.Collection.IEnumerable
'System.Collection.IDictionary
'System.Collection.ICollection
'System.Runtime.Serialization.ISerializable
'System.Runtime.Serialization.IDeserializationCallback
Megjegyzések
A .NET 6-os és korábbi verziókban a GetInterfaces metódus nem ad vissza interfészeket egy adott sorrendben, például betűrendben vagy deklarációs sorrendben. A kódnak nem szabad függenie attól, hogy a rendszer milyen sorrendben adja vissza a felületeket, mert ez a sorrend eltérő. A 7. .NET kezdve azonban a rendezés determinisztikus a szerelvény metaadatainak sorrendje alapján.
Ha az áram Type egy konstruktált általános típust jelöl, ez a metódus az Type objektumokat a megfelelő típusargumentumokkal helyettesített típusparaméterekkel adja vissza.
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.