System.Type.GetTypeFromCLSID 方法 (Guid, Boolean)

方法描述

获取与指定类标识符 (CLSID) 关联的类型,指定在加载该类型时如果发生错误是否引发异常。

语法定义(C# System.Type.GetTypeFromCLSID 方法 (Guid, Boolean) 的用法)

public static Type GetTypeFromCLSID(
	Guid clsid,
	bool throwOnError
)

参数/返回值

参数值/返回值 参数类型/返回类型 参数描述/返回描述
clsid System-Guid 要获取的类型的 CLSID。
throwOnError System-Boolean true 将引发所发生的任何异常。- 或 -false 将忽略所发生的任何异常。
返回值 System.Type System.__ComObject ,无论 CLSID 是否有效。

提示和注释

OutOfMemoryException 等异常将在为 throwOnError 指定 true 时引发,但它对于未注册的 CLSID 不会失败。

System.Type.GetTypeFromCLSID 方法 (Guid, Boolean)例子

下面的示例从本地主机检索与 CLSID 关联的类型,并指定在加载类型时如果出现错误是否引发异常。

using System;
class MyGetTypeFromCLSIDSample
{
    public static void Main()
    {
        try
        {
            // Create a GUID.
            Guid myGuid1 = new Guid("1DCD0710-0B41-11D3-A565-00C04F8EF6E3");
            // Get the type associated with the CLSID
            // and specify whether to throw an exception if an error occurs
            // while loading the type.
            Type myType1 =Type.GetTypeFromCLSID(myGuid1, true);
            Console.WriteLine("The GUID associated with myType1 is {0}.", myType1.GUID);
            Console.WriteLine("The type of the GUID is {0}.", myType1.ToString());

异常

异常 异常描述

命名空间

namespace: System

程序集: mscorlib(在 mscorlib.dll 中)

版本信息

.NET Framework 受以下版本支持:4、3.5、3.0、2.0、1.1、1.0 .NET Framework Client Profile 受以下版本支持:4、3.5 SP1

适用平台

Windows 7, Windows Vista SP1 或更高版本, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008(不支持服务器核心), Windows Server 2008 R2(支持 SP1 或更高版本的服务器核心), Windows Server 2003 SP2 .NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。