ManagedToNativeComInteropStubAttribute ManagedToNativeComInteropStubAttribute ManagedToNativeComInteropStubAttribute ManagedToNativeComInteropStubAttribute Class

定义

为用户在托管与 COM 互操作方案中自定义互操作存根提供支持。Provides support for user customization of interop stubs in managed-to-COM interop scenarios.

public ref class ManagedToNativeComInteropStubAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple=false, Inherited=false)]
[System.Runtime.InteropServices.ComVisible(false)]
[System.AttributeUsage(System.AttributeTargets.Method, Inherited=false)]
public sealed class ManagedToNativeComInteropStubAttribute : Attribute
type ManagedToNativeComInteropStubAttribute = class
    inherit Attribute
Public NotInheritable Class ManagedToNativeComInteropStubAttribute
Inherits Attribute
继承
ManagedToNativeComInteropStubAttributeManagedToNativeComInteropStubAttributeManagedToNativeComInteropStubAttributeManagedToNativeComInteropStubAttribute
属性

注解

此特性使互操作的开发人员具有封送处理有关的知识和互操作调用来执行以下操作的内部工作原理:This attribute enables interop developers who have knowledge about marshaling and the inner workings of interop calls to do the following:

  • 在生成时,而不是运行时充分利用自定义互操作存根 (stub)。Take advantage of customized interop stubs at build time instead of run time.

  • 调试自定义互操作存根 (stub)。Debug customized interop stubs.

  • 提供在运行时不提供存根封送处理功能。Provide marshaling capabilities within a stub that the runtime does not provide.

  • 提供特定于用户的方法分派的功能。Provide user-specific method dispatch capabilities.

在一个接口来指定相应的存根 (stub) 方法为托管到本机 COM 互操作的方法将该属性。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.

ManagedToNativeComInteropStubAttribute属性具有以下特征:The ManagedToNativeComInteropStubAttribute attribute has the following characteristics:

  • 该属性可以使用仅在从标记的接口方法上[ComImport]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.

  • 包含特性化的方法的程序集还必须包含自定义的存根 (stub)。The assembly that contains the attributed method must also contain the customized stub.

重载的存根方法都有效。Overloaded stub methods are valid. 虽然指定的类型和存根 (stub) 方法的名称,运行时将发现相应的存根 (stub)。Although you specify only the type and the name of the stub method, the runtime will discover the corresponding stub. 这是通过检查接口方法上的所有参数,然后再执行完整签名匹配的使用显式this指针。It does this by examining all the arguments on the interface method, and then performing full signature matching by using an explicit this pointer.

还有可能共享相同的存根 (stub) 方法; 接口中的多个方法但是,您应谨慎使用共享的存根。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.

备注

存根 (stub) 方法必须是静态的。Stub methods must be static.

您可以通知运行时在生成时,而不是使用以下 C# 代码的运行时使用自定义互操作存根 (stub):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);  
}  

然后可以使用以下代码以声明相应的存根 (stub) 方法:You could then use the following code to declare the corresponding stub method:

class TestStubClass  
{  
    internal static void ForwardTestStub(IMyInterface thisObject,  
             string arg) {…}  
}  

构造函数

ManagedToNativeComInteropStubAttribute(Type, String) ManagedToNativeComInteropStubAttribute(Type, String) ManagedToNativeComInteropStubAttribute(Type, String) ManagedToNativeComInteropStubAttribute(Type, String)

使用指定的类类型和方法名称初始化 ManagedToNativeComInteropStubAttribute 类的新实例。Initializes a new instance of the ManagedToNativeComInteropStubAttribute class with the specified class type and method name.

属性

ClassType ClassType ClassType ClassType

获取包含所需存根方法的类。Gets the class that contains the required stub method.

MethodName MethodName MethodName MethodName

获取存根方法的名称。Gets the name of the stub method.

TypeId TypeId TypeId TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。When implemented in a derived class, gets a unique identifier for this Attribute.

(Inherited from Attribute)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。Returns a value that indicates whether this instance is equal to a specified object.

(Inherited from Attribute)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

返回此实例的哈希代码。Returns the hash code for this instance.

(Inherited from Attribute)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(Inherited from Attribute)
Match(Object) Match(Object) Match(Object) Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(Inherited from Attribute)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

显式界面实现

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

(Inherited from Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface.

(Inherited from Attribute)
_Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(Inherited from Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

(Inherited from Attribute)

适用于