ComUnregisterFunctionAttribute 类

指定当注销用于 COM 的程序集时调用的方法;这可以用于注销过程中用户编写代码的执行。

**命名空间:**System.Runtime.InteropServices
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
<AttributeUsageAttribute(AttributeTargets.Method, Inherited:=False)> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class ComUnregisterFunctionAttribute
    Inherits Attribute
用法
Dim instance As ComUnregisterFunctionAttribute
[AttributeUsageAttribute(AttributeTargets.Method, Inherited=false)] 
[ComVisibleAttribute(true)] 
public sealed class ComUnregisterFunctionAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Method, Inherited=false)] 
[ComVisibleAttribute(true)] 
public ref class ComUnregisterFunctionAttribute sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Method, Inherited=false) */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class ComUnregisterFunctionAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Method, Inherited=false) 
ComVisibleAttribute(true) 
public final class ComUnregisterFunctionAttribute extends Attribute

备注

可将该属性应用于方法。

ComUnregisterFunctionAttribute 使您可以添加代码,以撤销注册方法所执行的操作。如果使用 ComRegisterFunctionAttribute 提供了注册方法,还必须提供注销方法,以撤销在注册方法中所进行的操作。只能为每个类提供一个注销方法。

当使用 程序集注册工具 (Regasm.exe) 或通过 RegistrationServices.UnregisterAssembly API 方法(直接或间接)注销公共语言运行库的包含程序集时,运行库将使用此属性调用该注销方法。具有此属性的方法可以具有任何可见性(公共、私有等),但必须是 static 的,并且必须采用一个 Type 参数以用于注销 Type

示例

下面的示例演示了如何将 ComRegisterFunctionAttributeComUnregisterFunctionAttribute 应用于方法,并在应用的同时加以适当的签名。

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
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.
   }
}
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.
   }

};
import System.*;
import System.Runtime.InteropServices.*;

public class MyClassThatNeedsToRegister
{
    /** @attribute ComRegisterFunctionAttribute()
     */
    public static void RegisterFunction(Type t)
    {
        //Insert code here.
    } //RegisterFunction

    /** @attribute ComUnregisterFunctionAttribute()
     */
    public static void UnregisterFunction(Type t)
    {
        //Insert code here.
    } //UnregisterFunction
} //MyClassThatNeedsToRegister
import System;
import System.Runtime.InteropServices;

public class MyClassThatNeedsToRegister
{
   ComRegisterFunctionAttribute public static function RegisterFunction(t : Type) : void 
   {
      //Insert code here.
   }
   
   ComUnregisterFunctionAttribute public static function UnregisterFunction(t : Type) : void
   {
      //Insert code here.
   }
}

继承层次结构

System.Object
   System.Attribute
    System.Runtime.InteropServices.ComUnregisterFunctionAttribute

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

ComUnregisterFunctionAttribute 成员
System.Runtime.InteropServices 命名空间
ComRegisterFunctionAttribute 类
RegistrationServices.UnregisterAssembly

其他资源

程序集注册工具 (Regasm.exe)