GuidAttribute Class

Definition

当不需要自动 GUID 时提供显式的 GuidSupplies an explicit Guid when an automatic GUID is undesirable.

public ref class GuidAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Delegate | System.AttributeTargets.Enum | System.AttributeTargets.Interface | System.AttributeTargets.Struct, Inherited=false)]
public sealed class GuidAttribute : Attribute
[System.Runtime.InteropServices.ComVisible(true)]
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Delegate | System.AttributeTargets.Enum | System.AttributeTargets.Interface | System.AttributeTargets.Struct, Inherited=false)]
public sealed class GuidAttribute : Attribute
type GuidAttribute = class
    inherit Attribute
Public NotInheritable Class GuidAttribute
Inherits Attribute
Inheritance
GuidAttribute
Attributes

Examples

下面的示例演示如何将 GuidAttribute 应用到使用固定 GUID 导出到 COM 的类。The following example demonstrates how to apply the GuidAttribute to a class that is exported to COM with a fixed GUID.

using namespace System;
using namespace System::Runtime::InteropServices;


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

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


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

Remarks

可以将此特性应用于程序集、接口、类、枚举、结构或委托,不过, tlbimp.exe (类型库导入程序)可以在导入类型库时应用此特性。You can apply this attribute to assemblies, interfaces, classes, enumerations, structures, or delegates, although the Tlbimp.exe (Type Library Importer) can apply it for you when it imports a type library.

传递给特性的字符串的格式必须为 Guid类型的可接受构造函数参数。The string passed to the attribute must be in a format that is an acceptable constructor argument for the type Guid. 若要避免与类型 Guid冲突,请 GuidAttribute 显式使用长名称。To avoid conflicts with the type Guid, use the long name GuidAttribute explicitly. 仅当类型必须具有特定 GUID 时,才使用显式 GUID。Only use an explicit GUID when a type must have a specific GUID. 如果省略该属性,则会自动分配一个 GUID。If the attribute is omitted, a GUID is assigned automatically.

Constructors

GuidAttribute(String)

用指定的 GUID 初始化 GuidAttribute 类的新实例。Initializes a new instance of the GuidAttribute class with the specified GUID.

Properties

TypeId

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

(Inherited from Attribute)
Value

获取类的 GuidGets the Guid of the class.

Methods

Equals(Object)

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

(Inherited from Attribute)
GetHashCode()

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

(Inherited from Attribute)
GetType()

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

(Inherited from Object)
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)

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

(Inherited from Attribute)
MemberwiseClone()

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

(Inherited from Object)
ToString()

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

(Inherited from Object)

Explicit Interface Implementations

_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)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。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)

检索对象提供的类型信息接口的数量(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)

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

(Inherited from Attribute)

Applies to

See also