Type.GUID 属性
获取与 Type 关联的 GUID。
**命名空间:**System
**程序集:**mscorlib(在 mscorlib.dll 中)
语法
声明
Public MustOverride ReadOnly Property GUID As Guid
用法
Dim instance As Type
Dim value As Guid
value = instance.GUID
public abstract Guid GUID { get; }
public:
virtual property Guid GUID {
Guid get () abstract;
}
/** @property */
public abstract Guid get_GUID ()
public abstract function get GUID () : Guid
属性值
与 Type 关联的 GUID。
备注
GUID 通过 GuidAttribute 属性与类型关联。
示例
下面的示例创建具有公共方法的类 MyClass1
,创建与 MyClass1
对应的 Type 对象,然后使用 Type 类的 GUID 属性获取 Guid 结构。
Imports System
Class MyGetTypeFromCLSID
Public Class MyClass1
Public Sub MyMethod1()
End Sub 'MyMethod1
End Class 'MyClass1
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 = CType(myType.GUID, Guid)
Console.WriteLine(("The name of the class is " + myType.ToString()))
Console.WriteLine(("The ClassId of MyClass is " + myType.GUID.ToString()))
End Sub 'Main
End Class 'MyGetTypeFromCLSID
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);
}
}
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 );
}
import System.*;
class MyGetTypeFromCLSID
{
public class MyClass1
{
public void MyMethod1()
{
} //MyMethod1
} //MyClass1
public static void main(String[] args)
{
// Get the type corresponding to the class MyClass.
Type myType = MyClass1.class.ToType();
// Get the object of the Guid.
Guid myGuid = (Guid)(myType.get_GUID());
Console.WriteLine("The name of the class is " + myType.ToString());
Console.WriteLine("The ClassId of MyClass is " + myType.get_GUID());
} //main
} //MyGetTypeFromCLSID
平台
Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0