Type.GUID Propriété

Définition

Obtient le GUID associé au Type.

public:
 abstract property Guid GUID { Guid get(); };
public abstract Guid GUID { get; }
member this.GUID : Guid
Public MustOverride ReadOnly Property GUID As Guid

Valeur de propriété

GUID associé au Type.

Implémente

Exemples

L’exemple suivant crée la classe MyClass1 avec une méthode publique, crée un Type objet correspondant et obtient la MyClass1 structure à Guidl’aide de la GUID propriété de la Type classe.

using System;

class MyGetTypeFromCLSID
{
    public class MyClass1
    {
        public void MyMethod1()
        {
        }
    }
    public static void Main()
    {
        // Get the type corresponding to the class MyClass.
        Type myType = typeof(MyClass1);
        // Get the object of the Guid.
        Guid myGuid =(Guid) myType.GUID;
        Console.WriteLine("The name of the class is "+myType.ToString());
        Console.WriteLine("The ClassId of MyClass is "+myType.GUID);				
    }
}
type MyClass1() =
    member _.MyMethod1() = ()

// Get the type corresponding to the class MyClass.
let myType = typeof<MyClass1>
// Get the object of the Guid.
let myGuid = myType.GUID
printfn $"The name of the class is {myType}"
printfn $"The ClassId of MyClass is {myType.GUID}"
Class MyGetTypeFromCLSID

    Public Class MyClass1

        Public Sub MyMethod1()
        End Sub

    End Class

    Public Shared Sub Main()
        ' Get the type corresponding to the class MyClass.
        Dim myType As Type = GetType(MyClass1)
        ' Get the object of the Guid.
        Dim myGuid As Guid = myType.GUID
        Console.WriteLine(("The name of the class is " + myType.ToString()))
        Console.WriteLine(("The ClassId of MyClass is " + myType.GUID.ToString()))
    End Sub
End Class

Remarques

Cette propriété retourne un GUID associé à un type à l’aide de l’attribut GuidAttribute . Si l’attribut est omis, un GUID est attribué automatiquement.

Le GUID retourné par cette propriété est généralement utilisé pour exposer un type à COM. Il n’est pas destiné à être utilisé comme identificateur unique du type.

S’applique à

Voir aussi