Type.GetInterface Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient une interface spécifique implémentée ou héritée par le Type actuel.
Surcharges
GetInterface(String, Boolean) |
En cas de substitution dans une classe dérivée, recherche l'interface spécifiée, en indiquant s'il faut faire une recherche qui ne respecte pas la casse pour le nom de l'interface. |
GetInterface(String) |
Recherche l'interface avec le nom spécifié. |
GetInterface(String, Boolean)
En cas de substitution dans une classe dérivée, recherche l'interface spécifiée, en indiquant s'il faut faire une recherche qui ne respecte pas la casse pour le nom de l'interface.
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
Paramètres
- name
- String
Chaîne contenant le nom de l'interface à obtenir. Pour les interfaces génériques, il s'agit du nom tronqué.
- ignoreCase
- Boolean
true
pour ignorer la casse de cette partie de name
qui spécifie le nom d'interface simple (la casse de la partie qui spécifie l'espace de noms doit être respectée).
- ou -
false
pour effectuer une recherche qui respecte la casse de toutes les parties dename
.
Retours
Objet qui représente l'interface ayant le nom spécifié, implémentée ou héritée par le Type actuel, s'il est trouvé ; sinon, null
.
Implémente
Exceptions
name
a la valeur null
.
Le Type actuel représente un type qui implémente la même interface générique avec des arguments de type différents.
Exemples
L’exemple de code suivant utilise la GetInterface(String, Boolean) méthode pour effectuer une recherche sans casse de la Hashtable classe pour l’interface IEnumerable .
L’exemple de code illustre également la GetInterface(String) surcharge de méthode et la GetInterfaceMap méthode.
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
Remarques
Le ignoreCase
paramètre s’applique uniquement au nom de l’interface simple, et non à l’espace de noms. La partie de ce paramètre spécifie que l’espace de name
noms doit avoir le cas approprié, ou l’interface n’est pas trouvée. Par exemple, la chaîne « System.icomparable » recherche l’interface IComparable , mais la chaîne « system.icomparable » ne le fait pas.
Si le courant Type représente un type générique construit, cette méthode retourne les Type paramètres de type remplacés par les arguments de type appropriés.
Si le courant Type représente un paramètre de type dans la définition d’un type générique ou d’une méthode générique, cette méthode recherche les contraintes d’interface et toutes les interfaces héritées des contraintes de classe ou d’interface.
Notes
Pour les interfaces génériques, le name
paramètre est le nom bascule, se terminant par un accent grave (`) et le nombre de paramètres de type. Cela est vrai pour les définitions d’interface génériques et les interfaces génériques construites. Par exemple, pour rechercher IExample<T>
(IExample(Of T)
dans Visual Basic) ou IExample<string>
(IExample(Of String)
dans Visual Basic), recherchez "IExample
1 " ».
Voir aussi
S’applique à
GetInterface(String)
Recherche l'interface avec le nom spécifié.
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
Paramètres
- name
- String
Chaîne contenant le nom de l'interface à obtenir. Pour les interfaces génériques, il s'agit du nom tronqué.
Retours
Objet qui représente l'interface ayant le nom spécifié, implémentée ou héritée par le Type actuel, s'il est trouvé ; sinon, null
.
Implémente
Exceptions
name
a la valeur null
.
Le Type actuel représente un type qui implémente la même interface générique avec des arguments de type différents.
Exemples
L’exemple de code suivant utilise la GetInterface(String) méthode pour rechercher la Hashtable classe pour l’interface IDeserializationCallback et répertorie les méthodes de l’interface.
L’exemple de code illustre également la GetInterface(String, Boolean) surcharge de méthode et la GetInterfaceMap méthode.
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
Remarques
La recherche name
est sensible à la casse.
Si le courant Type représente un type générique construit, cette méthode retourne les Type paramètres de type remplacés par les arguments de type appropriés.
Si le courant Type représente un paramètre de type dans la définition d’un type générique ou d’une méthode générique, cette méthode recherche les contraintes d’interface et toutes les interfaces héritées des contraintes de classe ou d’interface.
Notes
Pour les interfaces génériques, le name
paramètre est le nom bascule, se terminant par un accent grave (`) et le nombre de paramètres de type. Cela est vrai pour les définitions d’interface génériques et les interfaces génériques construites. Par exemple, pour rechercher IExample<T>
(IExample(Of T)
dans Visual Basic) ou IExample<string>
(IExample(Of String)
dans Visual Basic), recherchez "IExample`1"
.