InterfaceTypeAttribute 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指示 Managed 介面公開給 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
控制介面如何公開至 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 (型別程式庫匯出工具) 將 Managed 介面公開給 COM 作為雙重介面,讓您有延遲系結的彈性或早期系結的效能。 列舉 ComInterfaceType 可讓您覆寫預設行為,並只指定晚期系結或僅早期系結。 例如,您可以套用 InterfaceType (ComInterfaceType.InterfaceIsIDispatch)
至介面,以產生中繼資料,只限制呼叫端對晚期系結。 雖然衍生自 介面的 IDispatch
介面通常是雙重的, InterfaceIsIDispatch
但列舉成員只允許對介面方法進行晚期繫結呼叫。 此屬性不會影響介面的 Managed 檢視。 如需如何向 COM 公開介面的詳細資訊,請參閱 匯出的類型轉換。
Tlbimp.exe (型別程式庫匯入工具) 也會將此屬性套用至匯入的非dual 介面;它會套用適當的列舉成員,以指出介面僅分派或 IUnknown
-only。
建構函式
InterfaceTypeAttribute(ComInterfaceType) |
使用指定的 InterfaceTypeAttribute 列舉型別 (Enumeration) 成員,初始化 ComInterfaceType 類別的新執行個體。 |
InterfaceTypeAttribute(Int16) |
使用指定的 InterfaceTypeAttribute 列舉型別 (Enumeration) 成員,初始化 ComInterfaceType 類別的新執行個體。 |
屬性
TypeId |
在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。 (繼承來源 Attribute) |
Value |
取得描述介面應如何公開給 COM 的 ComInterfaceType 值。 |
方法
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) |
將一組名稱對應至一組對應的分派識別項 (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) |