GuidAttribute Class


Supplies 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
type GuidAttribute = class
    inherit Attribute
Public NotInheritable Class GuidAttribute
Inherits Attribute


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;

public ref class SampleClass
    // Insert class members here.
using System;
using System.Runtime.InteropServices;

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


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.

The string passed to the attribute must be in a format that is an acceptable constructor argument for the type Guid. To avoid conflicts with the type Guid, use the long name GuidAttribute explicitly. Only use an explicit GUID when a type must have a specific GUID. If the attribute is omitted, a GUID is assigned automatically.



Initializes a new instance of the GuidAttribute class with the specified GUID.



When implemented in a derived class, gets a unique identifier for this Attribute.

(Inherited from Attribute)

Gets the Guid of the class.



Returns a value that indicates whether this instance is equal to a specified object.

(Inherited from Attribute)

Returns the hash code for this instance.

(Inherited from Attribute)

Gets the Type of the current instance.

(Inherited from Object)

When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(Inherited from Attribute)

When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(Inherited from Attribute)

Creates a shallow copy of the current Object.

(Inherited from Object)

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)

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