InterfaceTypeAttribute 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指示在向 COM 公开时,托管接口是双接口、仅调度接口还是 IUnknown -only。
public ref class InterfaceTypeAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Interface, Inherited=false)]
public sealed class InterfaceTypeAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Interface, Inherited=false)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class InterfaceTypeAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Interface, Inherited=false)>]
type InterfaceTypeAttribute = class
inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Interface, Inherited=false)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type InterfaceTypeAttribute = class
inherit Attribute
Public NotInheritable Class InterfaceTypeAttribute
Inherits Attribute
- 继承
- 属性
示例
以下示例演示如何 InterfaceTypeAttribute 控制接口如何向 COM 公开。
using namespace System::Runtime::InteropServices;
//Interface is exposed to COM as dual.
interface class IMyInterface1{};
//Insert code here.
//Interface is exposed to COM as IDispatch.
[InterfaceTypeAttribute(ComInterfaceType::InterfaceIsIDispatch)]
interface class IMyInterface2{};
//Insert code here.
using System.Runtime.InteropServices;
//Interface is exposed to COM as dual.
interface IMyInterface1
{
//Insert code here.
}
//Interface is exposed to COM as IDispatch.
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
interface IMyInterface2
{
//Insert code here.
}
Imports System.Runtime.InteropServices
'Interface is exposed to COM as dual.
Interface IMyInterface1
'Insert code here.
End Interface
'Interface is exposed to COM as IDispatch.
<InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)> _
Interface IMyInterface2
'Insert code here.
End Interface
注解
可以将此属性应用于接口。
默认情况下, Tlbexp.exe(类型库导出程序) 将托管接口公开给 COM 作为双重接口,从而提供后期绑定的灵活性或早期绑定的性能。 通过 ComInterfaceType 枚举,可以重写默认行为,并仅指定后期绑定或仅提前绑定。 例如,可以应用于 InterfaceType (ComInterfaceType.InterfaceIsIDispatch) 接口来生成元数据,以仅将调用方限制为后期绑定。 尽管从 IDispatch 接口派生的接口通常是双重的, InterfaceIsIDispatch 但枚举成员只允许对接口方法进行后期绑定调用。 此属性对接口的托管视图没有影响。 有关如何向 COM 公开接口的其他信息,请参阅 导出的类型转换。
Tlbimp.exe(类型库导入程序)也适用于导入的非二元接口;它应用适当的枚举成员,以指示接口是仅调度的或 IUnknown -only 的。
构造函数
| 名称 | 说明 |
|---|---|
| InterfaceTypeAttribute(ComInterfaceType) |
使用指定的ComInterfaceType枚举成员初始化类的新实例InterfaceTypeAttribute。 |
| InterfaceTypeAttribute(Int16) |
使用指定的ComInterfaceType枚举成员初始化类的新实例InterfaceTypeAttribute。 |
属性
| 名称 | 说明 |
|---|---|
| TypeId |
在派生类中实现时,获取此 Attribute的唯一标识符。 (继承自 Attribute) |
| Value |
获取 ComInterfaceType 描述接口应如何向 COM 公开的值。 |
方法
| 名称 | 说明 |
|---|---|
| Equals(Object) |
返回一个值,该值指示此实例是否等于指定对象。 (继承自 Attribute) |
| GetHashCode() |
返回此实例的哈希代码。 (继承自 Attribute) |
| GetType() |
获取当前实例的 Type。 (继承自 Object) |
| IsDefaultAttribute() |
在派生类中重写时,指示此实例的值是否为派生类的默认值。 (继承自 Attribute) |
| Match(Object) |
在派生类中重写时,返回一个值,该值指示此实例是否等于指定对象。 (继承自 Attribute) |
| MemberwiseClone() |
创建当前 Object的浅表副本。 (继承自 Object) |
| ToString() |
返回一个表示当前对象的字符串。 (继承自 Object) |
显式接口实现
| 名称 | 说明 |
|---|---|
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
将一组名称映射到相应的调度标识符集。 (继承自 Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
检索对象的类型信息,该信息可用于获取接口的类型信息。 (继承自 Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
检索对象提供的类型信息接口数(0 或 1)。 (继承自 Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
提供对对象公开的属性和方法的访问。 (继承自 Attribute) |