Export (0) Print
Expand All

GuidAttribute Class

Supplies an explicit System.Guid when an automatic GUID is undesirable.

For a list of all members of this type, see GuidAttribute Members.

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

[Visual Basic]
<AttributeUsage(AttributeTargets.Assembly Or AttributeTargets.Class _
   Or AttributeTargets.Struct Or AttributeTargets.Enum Or _
   AttributeTargets.Interface Or AttributeTargets.Delegate)>
NotInheritable Public Class GuidAttribute
   Inherits Attribute
[C#]
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class
   | AttributeTargets.Struct | AttributeTargets.Enum |
   AttributeTargets.Interface | AttributeTargets.Delegate)]
public sealed class GuidAttribute : Attribute
[C++]
[AttributeUsage(AttributeTargets::Assembly |
   AttributeTargets::Class | AttributeTargets::Struct |
   AttributeTargets::Enum | AttributeTargets::Interface |
   AttributeTargets::Delegate)]
public __gc __sealed class GuidAttribute : public Attribute
[JScript]
public
   AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class |
   AttributeTargets.Struct | AttributeTargets.Enum |
   AttributeTargets.Interface | AttributeTargets.Delegate)
class GuidAttribute extends Attribute

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

You can apply this attribute to assemblies, interfaces, classes, enumerations, structures, or delegates, although the Type Library Importer (Tlbimp.exe) 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.

Example

The following example demonstrates how to apply the GuidAttribute to a class that is exported to COM with a fixed GUID.

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

[C#] 
[GuidAttribute("9ED54F84-A89D-4fcd-A854-44251E925F09")]

[C++] 
[GuidAttribute(S"9ED54F84-A89D-4fcd-A854-44251E925F09")]

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

Requirements

Namespace: System.Runtime.InteropServices

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: Mscorlib (in Mscorlib.dll)

See Also

GuidAttribute Members | System.Runtime.InteropServices Namespace | Guid | Type Library Importer (Tlbimp.exe)

Show:
© 2014 Microsoft