ComUnregisterFunctionAttribute ComUnregisterFunctionAttribute ComUnregisterFunctionAttribute ComUnregisterFunctionAttribute Class

定义

指定从 COM 中注销使用的程序集时要调用的方法;这可以在注销过程中执行用户编写的代码。Specifies the method to call when you unregister an assembly for use from COM; this allows for the execution of user-written code during the unregistration process.

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

示例

下面的示例演示如何将ComRegisterFunctionAttributeComUnregisterFunctionAttribute到具有合适签名的方法。The following example demonstrates applying 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
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.

ComUnregisterFunctionAttribute 可以添加代码,以撤消注册方法执行的操作。ComUnregisterFunctionAttribute enables you to add code that reverses the operations performed by a registration method. 如果将应用ComRegisterFunctionAttribute提供注册方法,您还应提供注销方法,以撤消在此注册方法中完成的操作。If you apply the ComRegisterFunctionAttribute to provide a registration method, you should also provide an unregistration method to reverse the operations done in the registration method. 您可以为类只有一个注销方法。You can have only one unregistration method for a class.

.NET framework: 公共语言运行时及其包含的程序集未 (直接或间接) 注册与调用具有此特性的方法Regasm.exe (程序集注册) 工具)或通过RegistrationServices.RegisterAssembly方法。.NET Framework: The common language runtime calls the method with this attribute when its containing assembly is unregistered (directly or indirectly) with the Regasm.exe (Assembly Registration) tool) or through the RegistrationServices.RegisterAssembly method.

.NET core: 公共语言运行时调用具有此特性的方法时通过注销其包含程序集的 COM 主机RegSvr32.exe 工具.NET Core: The common language runtime calls the method with this attribute when its containing assembly's COM host is unregistered via the RegSvr32.exe tool.

构造函数

ComUnregisterFunctionAttribute() ComUnregisterFunctionAttribute() ComUnregisterFunctionAttribute() ComUnregisterFunctionAttribute()

初始化 ComUnregisterFunctionAttribute 类的新实例。Initializes a new instance of the ComUnregisterFunctionAttribute class.

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。Returns a value that indicates whether this instance is equal to a specified object.

(Inherited from Attribute)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

返回此实例的哈希代码。Returns the hash code for this instance.

(Inherited from Attribute)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(Inherited from Attribute)
Match(Object) Match(Object) Match(Object) Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(Inherited from Attribute)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

显式界面实现

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

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

(Inherited from Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface.

(Inherited from Attribute)
_Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(Inherited from Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

(Inherited from Attribute)

属性

TypeId TypeId TypeId TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。When implemented in a derived class, gets a unique identifier for this Attribute.

(Inherited from Attribute)

适用于

另请参阅