ComRegisterFunctionAttribute 類別

定義

指定當您登錄來自 COM 的所用組件 (Assembly) 時要呼叫的方法;這個方法可讓您在登錄程序期間執行使用者撰寫的程式碼。Specifies the method to call when you register an assembly for use from COM; this enables the execution of user-written code during the registration process.

public ref class ComRegisterFunctionAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Method, Inherited=false)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class ComRegisterFunctionAttribute : Attribute
type ComRegisterFunctionAttribute = class
    inherit Attribute
Public NotInheritable Class ComRegisterFunctionAttribute
Inherits Attribute
繼承
ComRegisterFunctionAttribute
屬性

範例

下列範例示範如何將 ComRegisterFunctionAttributeComUnregisterFunctionAttribute 套用至具有適當簽章的方法。The following example demonstrates how to apply ComRegisterFunctionAttribute and ComUnregisterFunctionAttribute to methods with the appropriate signature.

using namespace System;
using namespace System::Runtime::InteropServices;
public ref class MyClassThatNeedsToRegister
{
public:

   [ComRegisterFunctionAttribute]
   static void RegisterFunction( Type^ t )
   {
      
      //Insert code here.
   }


   [ComUnregisterFunctionAttribute]
   static void UnregisterFunction( Type^ t )
   {
      
      //Insert code here.
   }

};

using System;
using System.Runtime.InteropServices;

public class MyClassThatNeedsToRegister
{
   [ComRegisterFunctionAttribute]
   public static void RegisterFunction(Type t)
   {
      //Insert code here.
   }
   
   [ComUnregisterFunctionAttribute]
   public static void UnregisterFunction(Type t)
   {
      //Insert code here.
   }
}
Imports System.Runtime.InteropServices

Public Class MyClassThatNeedsToRegister
    
    <ComRegisterFunctionAttribute()> Public Shared Sub _
      RegisterFunction(t As Type)
        'Insert code here.
    End Sub
    
    <ComUnregisterFunctionAttribute()> Public Shared Sub _
      UnregisterFunction(t As Type)
        'Insert code here.
    End Sub
End Class

備註

您可以將此屬性套用至方法。You can apply this attribute to methods.

ComRegisterFunctionAttribute 可讓您新增任意註冊程式碼,以滿足 COM 用戶端的需求。ComRegisterFunctionAttribute enables you to add arbitrary registration code to accommodate the requirements of COM clients. 例如,您可以使用 Microsoft.Win32 命名空間中的註冊功能來更新登錄。For example, you can update the registry using registration functions from the Microsoft.Win32 namespace. 如果您提供註冊方法,您也應該將 System.Runtime.InteropServices.ComUnregisterFunctionAttribute 套用至取消註冊方法,這會反轉在註冊方法中完成的作業。If you provide a registration method, you should also apply System.Runtime.InteropServices.ComUnregisterFunctionAttribute to an unregistration method, which reverses the operations done in the registration method.

.NET Framework: 通用語言執行平臺會在其內含元件以Regasm (元件註冊)工具註冊(直接或間接)時,或透過 RegistrationServices.RegisterAssembly 方法,呼叫具有這個屬性的方法。.NET Framework: The common language runtime calls the method with this attribute when its containing assembly is registered (directly or indirectly) with the Regasm.exe (Assembly Registration) tool) or through the RegistrationServices.RegisterAssembly method.

.Net Core: 通用語言執行平臺會在其包含元件的 COM 主機透過RegSvr32 工具註冊時,使用這個屬性來呼叫方法。.NET Core: The common language runtime calls the method with this attribute when its containing assembly's COM host is registered via the RegSvr32.exe tool.

這個屬性只能套用至具有下列特性的方法:This attribute can be applied only to methods that have the following characteristics:

  • 範圍:任何(公用、私用等等)。Scope: Any (public, private, and so on).

  • 類型:staticType: static.

  • Parameters:接受單一 Type 參數或 String 參數類型。Parameters: Accepts a single Type parameter or a String parameter type.

  • 傳回類型: voidReturn type: void.

建構函式

ComRegisterFunctionAttribute()

初始化 ComRegisterFunctionAttribute 類別的新執行個體。Initializes a new instance of the ComRegisterFunctionAttribute class.

屬性

TypeId

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

(繼承來源 Attribute)

方法

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)

適用於

另請參閱