InterfaceTypeAttribute 类

定义

指示向 COM 公开时,托管接口是双重的、仅支持调度的、还是仅支持 IUnknown 的。

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
属性

示例

以下示例演示如何 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)

适用于

另请参阅