InterfaceTypeAttribute 類別

定義

指出當公開給 COM 時,Managed 介面為雙重、僅限分派或 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
屬性

範例

以下範例展示了介面如何 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 枚舉成員只允許對介面方法進行晚界呼叫。 此屬性不影響介面的管理視圖。

Tlbimp.exe(型別函式庫匯入器)也會將此屬性套用於匯入的非對偶介面;它套用適當的枚舉成員來表示介面僅派遣或IUnknown僅派遣。

建構函式

名稱 Description
InterfaceTypeAttribute(ComInterfaceType)

初始化一個新的類別實例 InterfaceTypeAttribute ,並使用指定的 ComInterfaceType 列舉成員。

InterfaceTypeAttribute(Int16)

初始化一個新的類別實例 InterfaceTypeAttribute ,並使用指定的 ComInterfaceType 列舉成員。

屬性

名稱 Description
TypeId

在衍生類別中實作時,取得這個 Attribute的唯一標識碼。

(繼承來源 Attribute)
Value

取得 ComInterfaceType 描述介面應該如何暴露於 COM 的值。

方法

名稱 Description
Equals(Object)

傳回值,這個值表示這個實例是否等於指定的物件。

(繼承來源 Attribute)
GetHashCode()

傳回這個實例的哈希碼。

(繼承來源 Attribute)
GetType()

取得目前實例的 Type

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,指出這個實例的值是否為衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,傳回值,指出這個實例是否等於指定的物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)

明確介面實作

名稱 Description
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取 物件的型別資訊,可用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開屬性和方法的存取權。

(繼承來源 Attribute)

適用於

另請參閱