Type.GetInterfaceMap(Type) Método
Definição
Retorna um mapeamento de interface para o tipo de interface especificado.Returns an interface mapping for the specified interface type.
public:
virtual System::Reflection::InterfaceMapping GetInterfaceMap(Type ^ interfaceType);
public virtual System.Reflection.InterfaceMapping GetInterfaceMap (Type interfaceType);
[System.Runtime.InteropServices.ComVisible(true)]
public virtual System.Reflection.InterfaceMapping GetInterfaceMap (Type interfaceType);
abstract member GetInterfaceMap : Type -> System.Reflection.InterfaceMapping
override this.GetInterfaceMap : Type -> System.Reflection.InterfaceMapping
[<System.Runtime.InteropServices.ComVisible(true)>]
abstract member GetInterfaceMap : Type -> System.Reflection.InterfaceMapping
override this.GetInterfaceMap : Type -> System.Reflection.InterfaceMapping
Public Overridable Function GetInterfaceMap (interfaceType As Type) As InterfaceMapping
Parâmetros
- interfaceType
- Type
O tipo de interface para o qual um mapeamento será recuperado.The interface type to retrieve a mapping for.
Retornos
Um objeto que representa o mapeamento de interface para interfaceType.An object that represents the interface mapping for interfaceType.
Implementações
- Atributos
Exceções
interfaceType não é implementado pelo tipo atual.interfaceType is not implemented by the current type.
- ou --or-
O argumento interfaceType não faz referência a uma interface.The interfaceType argument does not refer to an interface.
- ou --or-
A instância atual ou argumento interfaceType é um tipo genérico aberto. Ou seja, a propriedade ContainsGenericParameters retorna true.The current instance or interfaceType argument is an open generic type; that is, the ContainsGenericParameters property returns true.
- ou --or-
interfaceType é uma interface genérica e o tipo atual é um tipo de matriz.interfaceType is a generic interface, and the current type is an array type.
interfaceType é null.interfaceType is null.
O Type atual representa um parâmetro de tipo genérico, ou seja, IsGenericParameter é true.The current Type represents a generic type parameter; that is, IsGenericParameter is true.
O método chamado não é suportado na classe base.The invoked method is not supported in the base class. As classes derivadas devem fornecer uma implementação.Derived classes must provide an implementation.
Exemplos
O exemplo a seguir chama o GetInterfaceMap método para determinar como a IFormatProvider interface é mapeada para CultureInfo métodos e como a IAppDomainSetup interface é mapeada para AppDomainSetup Propriedades.The following example calls the GetInterfaceMap method to determine how the IFormatProvider interface maps to CultureInfo methods, and how the IAppDomainSetup interface maps to AppDomainSetup properties. Observe que, como a IAppDomainSetup interface define um conjunto de propriedades, o InterfaceMapping objeto retornado inclui MethodInfo objetos separados para acessadores get e set de uma propriedade.Note that, because the IAppDomainSetup interface defines a set of properties, the returned InterfaceMapping object includes separate MethodInfo objects for a property's get and set accessors.
using System;
using System.Globalization;
using System.Reflection;
public class Example
{
public static void Main()
{
Type[] interf = { typeof(IFormatProvider), typeof(IAppDomainSetup) };
Type[] impl = { typeof(CultureInfo), typeof(AppDomainSetup) };
for (int ctr = 0; ctr < interf.Length; ctr++)
ShowInterfaceMapping(interf[ctr], impl[ctr]);
}
private static void ShowInterfaceMapping(Type intType, Type implType)
{
InterfaceMapping map = implType.GetInterfaceMap(intType);
Console.WriteLine("Mapping of {0} to {1}: ", map.InterfaceType, map.TargetType);
for (int ctr = 0; ctr < map.InterfaceMethods.Length; ctr++) {
MethodInfo im = map.InterfaceMethods[ctr];
MethodInfo tm = map.TargetMethods[ctr];
Console.WriteLine(" {0} --> {1}", im.Name,tm.Name);
}
Console.WriteLine();
}
}
// The example displays the following output:
// Mapping of System.IFormatProvider to System.Globalization.CultureInfo:
// GetFormat --> GetFormat
//
// Mapping of System.IAppDomainSetup to System.AppDomainSetup:
// get_ApplicationBase --> get_ApplicationBase
// set_ApplicationBase --> set_ApplicationBase
// get_ApplicationName --> get_ApplicationName
// set_ApplicationName --> set_ApplicationName
// get_CachePath --> get_CachePath
// set_CachePath --> set_CachePath
// get_ConfigurationFile --> get_ConfigurationFile
// set_ConfigurationFile --> set_ConfigurationFile
// get_DynamicBase --> get_DynamicBase
// set_DynamicBase --> set_DynamicBase
// get_LicenseFile --> get_LicenseFile
// set_LicenseFile --> set_LicenseFile
// get_PrivateBinPath --> get_PrivateBinPath
// set_PrivateBinPath --> set_PrivateBinPath
// get_PrivateBinPathProbe --> get_PrivateBinPathProbe
// set_PrivateBinPathProbe --> set_PrivateBinPathProbe
// get_ShadowCopyDirectories --> get_ShadowCopyDirectories
// set_ShadowCopyDirectories --> set_ShadowCopyDirectories
// get_ShadowCopyFiles --> get_ShadowCopyFiles
// set_ShadowCopyFiles --> set_ShadowCopyFiles
Imports System.Globalization
Imports System.Reflection
Module Example
Public Sub Main()
Dim int() As Type = { GetType(IFormatProvider), GetType(IAppDomainSetup) }
Dim impl() As Type = { GetType(CultureInfo), GetType(AppDomainSetup) }
For ctr As Integer = 0 To int.Length - 1
ShowInterfaceMapping(int(ctr), impl(ctr))
Next
End Sub
Private Sub ShowInterfaceMapping(intType As Type, implType As Type)
Dim map As InterfaceMapping = implType.GetInterfaceMap(intType)
Console.WriteLine("Mapping of {0} to {1}: ", map.InterfaceType, map.TargetType)
For ctr As Integer = 0 To map.InterfaceMethods.Length - 1
Dim im As MethodInfo = map.InterfaceMethods(ctr)
Dim tm As MethodInfo = map.TargetMethods(ctr)
Console.WriteLine(" {0} --> {1}", im.Name,tm.Name)
Next
Console.WriteLine()
End Sub
End Module
' The example displays the following output:
' Mapping of System.IFormatProvider to System.Globalization.CultureInfo:
' GetFormat --> GetFormat
'
' Mapping of System.IAppDomainSetup to System.AppDomainSetup:
' get_ApplicationBase --> get_ApplicationBase
' set_ApplicationBase --> set_ApplicationBase
' get_ApplicationName --> get_ApplicationName
' set_ApplicationName --> set_ApplicationName
' get_CachePath --> get_CachePath
' set_CachePath --> set_CachePath
' get_ConfigurationFile --> get_ConfigurationFile
' set_ConfigurationFile --> set_ConfigurationFile
' get_DynamicBase --> get_DynamicBase
' set_DynamicBase --> set_DynamicBase
' get_LicenseFile --> get_LicenseFile
' set_LicenseFile --> set_LicenseFile
' get_PrivateBinPath --> get_PrivateBinPath
' set_PrivateBinPath --> set_PrivateBinPath
' get_PrivateBinPathProbe --> get_PrivateBinPathProbe
' set_PrivateBinPathProbe --> set_PrivateBinPathProbe
' get_ShadowCopyDirectories --> get_ShadowCopyDirectories
' set_ShadowCopyDirectories --> set_ShadowCopyDirectories
' get_ShadowCopyFiles --> get_ShadowCopyFiles
' set_ShadowCopyFiles --> set_ShadowCopyFiles
Comentários
O mapa de interface denota como uma interface é mapeada para os membros reais em uma classe que implementa essa interface.The interface map denotes how an interface is mapped into the actual members on a class that implements that interface.
Se o atual Type representar um tipo genérico construído, os parâmetros de tipo serão substituídos pelos argumentos de tipo apropriados nos elementos do InterfaceMapping retornado por esse método.If the current Type represents a constructed generic type, type parameters are replaced by the appropriate type arguments in the elements of the InterfaceMapping returned by this method.