Type.GUID Vlastnost

Definice

Získá identifikátor GUID přidružený k Type.

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

Hodnota vlastnosti

Identifikátor GUID přidružený k .Type

Implementuje

Příklady

Následující příklad vytvoří třídu MyClass1 pomocí veřejné metody, vytvoří Type objekt odpovídající objektu MyClass1a získá Guid strukturu pomocí GUID vlastnosti Type třídy.

using namespace System;
ref class MyGetTypeFromCLSID
{
public:
   ref class MyClass1
   {
   public:
      void MyMethod1(){}
   };
};

int main()
{
   
   // Get the type corresponding to the class MyClass.
   Type^ myType = MyGetTypeFromCLSID::MyClass1::typeid;
   
   // Get the Object* of the Guid.
   Guid myGuid = (Guid)myType->GUID;
   Console::WriteLine( "The name of the class is {0}", myType );
   Console::WriteLine( "The ClassId of MyClass is {0}", myType->GUID );
}
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

Poznámky

Tato vlastnost vrátí identifikátor GUID, který je přidružený k typu pomocí atributu GuidAttribute . Pokud je atribut vynechán, identifikátor GUID se přiřadí automaticky.

Identifikátor GUID vrácený touto vlastností se obvykle používá ke zveřejnění typu modelu COM. Není určen k použití jako jedinečný identifikátor typu.

Platí pro

Viz také