GuidAttribute 类

当不需要自动 GUID 时提供显式的 System.Guid

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

语法

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

备注

可将此属性应用于程序集、接口、类、枚举、结构或委托,不过 类型库导入程序 (Tlbimp.exe) 在导入类型库时将为您应用此属性。

传递给属性的字符串必须符合 Guid 类型可接受的构造函数参数格式。为避免与 Guid 类型冲突,请显式使用长名 GuidAttribute。仅当类型必须有特定的 GUID 时才应使用显式的 GUID。如果省略该属性,则会自动分配一个 GUID。

示例

下面的示例演示了如何将 GuidAttribute 应用于使用固定 GUID 导出到 COM 的类。

Imports System
Imports System.Runtime.InteropServices


 <GuidAttribute("9ED54F84-A89D-4fcd-A854-44251E925F09")> _
 Public Class SampleClass
     ' Insert class members here.
 End Class
using System;
using System.Runtime.InteropServices;


[GuidAttribute("9ED54F84-A89D-4fcd-A854-44251E925F09")]
public class SampleClass 
{
    // Insert class members here.
}
using namespace System;
using namespace System::Runtime::InteropServices;


[GuidAttribute("9ED54F84-A89D-4fcd-A854-44251E925F09")]
public ref class SampleClass
{
    // Insert class members here.
};
import System.*;
import System.Runtime.InteropServices.*;


/** @attribute GuidAttribute("9ED54F84-A89D-4fcd-A854-44251E925F09")
 */

public class SampleClass
{
  // Insert class members here.  
} 
import System
import System.Runtime.InteropServices


 public GuidAttribute("9ED54F84-A89D-4fcd-A854-44251E925F09")
 class SampleClass{
     // Insert class members here
 }

继承层次结构

System.Object
   System.Attribute
    System.Runtime.InteropServices.GuidAttribute

线程安全

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

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、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

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

GuidAttribute 成员
System.Runtime.InteropServices 命名空间
Guid

其他资源

类型库导入程序 (Tlbimp.exe)