IDispatchImplAttribute 類別

定義

警告

此 API 現已淘汰。

指示在顯露雙重介面 (Dual Interface) 和 COM 的分配介面 (Dispinterface) 時,Common Language Runtime 使用哪個 IDispatch 實作。Indicates which IDispatch implementation the common language runtime uses when exposing dual interfaces and dispinterfaces to COM.

public ref class IDispatchImplAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class, Inherited=false)]
[System.Obsolete("This attribute is deprecated and will be removed in a future version.", false)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class IDispatchImplAttribute : Attribute
type IDispatchImplAttribute = class
    inherit Attribute
Public NotInheritable Class IDispatchImplAttribute
Inherits Attribute
繼承
IDispatchImplAttribute
屬性

範例

下列範例示範如何IDispatchImplAttribute套用以選取 common language runtime 所提供的IDispatch執行。The following example demonstrates how to apply IDispatchImplAttribute to select the IDispatch implementation supplied by the common language runtime.

using namespace System;
using namespace System::Runtime::InteropServices;

// by default all classes in this assembly will use COM implementaion
//   // But this class will use runtime implementaion

[assembly:IDispatchImpl(IDispatchImplType::CompatibleImpl)];
[IDispatchImpl(IDispatchImplType::InternalImpl)]
ref class MyClass{};
using System;
using System.Runtime.InteropServices;
// by default all classes in this assembly will use COM implementaion 
[assembly:IDispatchImpl(IDispatchImplType.CompatibleImpl)]

namespace MyNamespace
{
    // But this class will use runtime implementaion
    [IDispatchImpl(IDispatchImplType.InternalImpl)]
    class MyClass
    {
        //
    }
}

Imports System.Runtime.InteropServices
' by default all classes in this assembly will use COM implementaion 
<Assembly: IDispatchImpl(IDispatchImplType.CompatibleImpl)> 

Module MyNamespace
    ' But this class will use runtime implementaion
    <IDispatchImpl(IDispatchImplType.InternalImpl)> _
    Public Class c
        '
    End Class

End Module

備註

您可以將此屬性套用至類別或元件。You can apply this attribute to classes or assemblies.

只有在需要明確的執行時, 才應該設定這個屬性。This attribute should only be set when an explicit implementation is required. 當您將屬性設定為CompatibleImplIDispatch , 會藉由將物件的型別資訊傳遞給 COM 的CreateStdDispatch API 來提供執行。When you set the attribute to CompatibleImpl, the IDispatch implementation is supplied by passing the type information for the object to COM's CreateStdDispatch API. 當您將屬性設定為InternalImpl時, IDispatch就會由 common language runtime 提供實作為。When you set the attribute to InternalImpl, the IDispatch implementation is supplied by the common language runtime. 將屬性設定為SystemDefinedImpl , 可讓執行時間選擇適當的執行方式。Setting the attribute to SystemDefinedImpl allows the runtime to choose the appropriate implementation. 在元件上使用屬性時, 屬性會套用至元件中定義的所有類別。When using the attribute on an assembly, the attribute applies to all classes defined within the assembly. 在個別類別上使用屬性時, 屬性只會套用至該類別所公開的介面, 並覆寫任何元件層級設定。When using the attribute on an individual class, the attribute applies only to the interfaces exposed by that class and overrides any assembly-level setting.

建構函式

IDispatchImplAttribute(IDispatchImplType)

使用指定的 IDispatchImplType 值來初始化 IDispatchImplAttribute 類別的新執行個體。Initializes a new instance of the IDispatchImplAttribute class with specified IDispatchImplType value.

IDispatchImplAttribute(Int16)

使用指定的 IDispatchImplType 值來初始化 IDispatchImplAttribute 類別的新執行個體。Initializes a new instance of the IDispatchImplAttribute class with specified IDispatchImplType value.

屬性

TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。When implemented in a derived class, gets a unique identifier for this Attribute.

(繼承來源 Attribute)
Value

取得類別所使用的 IDispatchImplType 值。Gets the IDispatchImplType value used by the class.

方法

Equals(Object)

傳回值,這個值指出此執行個體是否與指定的物件相等。Returns a value that indicates whether this instance is equal to a specified object.

(繼承來源 Attribute)
GetHashCode()

傳回這個執行個體的雜湊碼。Returns the hash code for this instance.

(繼承來源 Attribute)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

明確介面實作

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

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。Maps a set of names to a corresponding set of dispatch identifiers.

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

擷取物件的類型資訊,可以用來取得介面的類型資訊。Retrieves the type information for an object, which can be used to get the type information for an interface.

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

擷取物件提供的類型資訊介面數目 (0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

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

提供物件所公開的屬性和方法的存取權。Provides access to properties and methods exposed by an object.

(繼承來源 Attribute)

適用於

另請參閱