Classe ManagedToNativeComInteropStubAttribute
Dá suporte para personalização do usuário de stubs de interoperabilidade em cenários de interoperabilidade gerenciada para COM.
Namespace: System.Runtime.InteropServices
Assembly: mscorlib (em mscorlib.dll)
Hierarquia de Herança
System.Object
System.Attribute
System.Runtime.InteropServices.ManagedToNativeComInteropStubAttribute
Sintaxe
[AttributeUsageAttribute(AttributeTargets.Method, Inherited = false,
AllowMultiple = false)]
[ComVisibleAttribute(false)]
public sealed class ManagedToNativeComInteropStubAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Method, Inherited = false,
AllowMultiple = false)]
[ComVisibleAttribute(false)]
public ref class ManagedToNativeComInteropStubAttribute sealed : Attribute
[<Sealed>]
[<AttributeUsageAttribute(AttributeTargets.Method, Inherited = false,
AllowMultiple = false)>]
[<ComVisibleAttribute(false)>]
type ManagedToNativeComInteropStubAttribute =
class
inherit Attribute
end
<AttributeUsageAttribute(AttributeTargets.Method, Inherited := False,
AllowMultiple := False)>
<ComVisibleAttribute(False)>
Public NotInheritable Class ManagedToNativeComInteropStubAttribute
Inherits Attribute
Construtores
Nome | Descrição | |
---|---|---|
ManagedToNativeComInteropStubAttribute(Type, String) | Inicializa uma nova instância de ManagedToNativeComInteropStubAttribute classe com o nome de tipo e o método da classe especificada. |
Propriedades
Nome | Descrição | |
---|---|---|
ClassType | Obtém a classe que contém o método de stub necessário. |
|
MethodName | Obtém o nome do método stub. |
|
TypeId | Quando implementado em uma classe derivada, obtém um identificador exclusivo para este Attribute.(Herdado de Attribute.) |
Métodos
Nome | Descrição | |
---|---|---|
Equals(Object) | Esta API dá suporte à infraestrutura produto e não se destina a ser usada diretamente do seu código. Retorna um valor que indica se essa instância é igual a um objeto especificado.(Herdado de Attribute.) |
|
GetHashCode() | Retorna o código hash para essa instância.(Herdado de Attribute.) |
|
GetType() | ||
IsDefaultAttribute() | Quando substituído em uma classe derivada, indica se o valor dessa instância é o valor padrão para a classe derivada.(Herdado de Attribute.) |
|
Match(Object) | Quando substituído em uma classe derivada, retorna um valor que indica se essa instância é igual a um objeto especificado.(Herdado de Attribute.) |
|
ToString() | Retorna uma cadeia de caracteres que representa o objeto atual.(Herdado de Object.) |
Implementações Explícitas da Interface
Nome | Descrição | |
---|---|---|
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) | Mapeia um conjunto de nomes para um conjunto correspondente de identificadores de expedição.(Herdado de Attribute.) |
|
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) | Recupera as informações de tipo para um objeto, que pode ser usado para obter as informações de tipo para uma interface.(Herdado de Attribute.) |
|
_Attribute.GetTypeInfoCount(UInt32) | Retorna o número de interfaces de informações do tipo que um objeto fornece (0 ou 1).(Herdado de Attribute.) |
|
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) | Fornece acesso a propriedades e métodos expostos por um objeto.(Herdado de Attribute.) |
Comentários
This attribute enables interop developers who have knowledge about marshaling and the inner workings of interop calls to do the following:
Take advantage of customized interop stubs at build time instead of run time.
Debug customized interop stubs.
Provide marshaling capabilities within a stub that the runtime does not provide.
Provide user-specific method dispatch capabilities.
You apply the attribute on a method in an interface to specify a corresponding stub method for managed-to-native COM interop.
If this attribute is encountered during run time, the common language runtime does not dynamically generate an interop stub. Instead, it invokes the custom stub that was created at build time.
The T:System.Runtime.InteropServices.ManagedToNativeComInteropStubAttribute attribute has the following characteristics:
The attribute can be used only on methods from interfaces that are marked [ComImport]. If the attribute is applied to non-interface types, it is ignored by the runtime.
The attribute can be used only once on the same method in an interface. If it is used more than once, the compiler generates a duplicated attribute error.
The attribute is not inheritable from a base interface. Derived interfaces must explicitly assign the attribute.
The assembly that contains the attributed method must also contain the customized stub.
Overloaded stub methods are valid. Although you specify only the type and the name of the stub method, the runtime will discover the corresponding stub. It does this by examining all the arguments on the interface method, and then performing full signature matching by using an explicit this pointer.
It is also possible for multiple methods in an interface to share the same stub method; however, you should be careful when you use shared stubs.
Dica
Stub methods must be static.
You could inform the runtime to use a customized interop stub at build time instead of run time with the following C# code:
[ComImport]
interface IMyInterface
{
[ManagedToNativeComInteropStubAttribute(typeof(TestStubClass),
"ForwardTestStub")]
void GetString (string arg);
}
You could then use the following code to declare the corresponding stub method:
class TestStubClass
{
internal static void ForwardTestStub(IMyInterface thisObject,
string arg) {…}
}
Informações de Versão
.NET Framework
Disponível desde 4.0
Acesso thread-safe
Quaisquer membros estáticos públicos ( Compartilhado no Visual Basic) desse tipo são thread-safe. Não há garantia de que qualquer membro de instância seja thread-safe.
Confira Também
Namespace System.Runtime.InteropServices
Retornar ao início