Leer en inglés

Compartir a través de


Type.GUID Propiedad

Definición

Obtiene el GUID asociado al objeto Type.

C#
public abstract Guid GUID { get; }

Valor de propiedad

GUID asociado al objeto Type.

Implementaciones

Ejemplos

En el ejemplo siguiente se crea la clase MyClass1 con un método público, se crea un Type objeto correspondiente a MyClass1y se obtiene la Guid estructura mediante la GUID propiedad de la Type clase .

C#
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);				
    }
}

Comentarios

Esta propiedad devuelve un GUID asociado a un tipo mediante el GuidAttribute atributo . Si se omite el atributo, se asigna automáticamente un GUID.

El GUID devuelto por esta propiedad se usa normalmente para exponer un tipo a COM. No está pensado para usarse como identificador único del tipo.

Se aplica a

Producto Versiones
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Consulte también