ComRegisterFunctionAttribute 类

定义

指定从 COM 中注册使用的程序集时要调用的方法;这样可以在注册进程中执行用户编写的代码。

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

示例

以下示例演示如何将 和 ComUnregisterFunctionAttribute 应用于ComRegisterFunctionAttribute具有相应签名的方法。

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

注解

可以将此属性应用于方法。

ComRegisterFunctionAttribute 使你能够添加任意注册代码以满足 COM 客户端的要求。 例如,可以使用命名空间中的注册函数 Microsoft.Win32 更新注册表。 如果提供注册方法,则还应应用于 System.Runtime.InteropServices.ComUnregisterFunctionAttribute 取消注册方法,该方法将反转在注册方法中执行的操作。

.NET Framework:当使用Regasm.exe (程序集注册 () 工具 ) 或通过 RegistrationServices.RegisterAssembly 方法直接或间接) 包含它的程序集时,公共语言运行时使用此属性调用该方法。

.NET Core: 当通过 RegSvr32.exe 工具注册包含程序集的 COM 主机时,公共语言运行时使用此属性调用 方法。

此属性只能应用于具有以下特征的方法:

  • 范围:任何 (公共、专用等) 。

  • 键入:static

  • 参数:接受单个 Type 参数或 String 参数类型。

  • 返回类型: void

构造函数

ComRegisterFunctionAttribute()

初始化 ComRegisterFunctionAttribute 类的新实例。

属性

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。

(继承自 Attribute)

方法

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)

适用于

另请参阅