Type.GetTypeFromProgID 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得與指定之程式標識碼 (ProgID) 相關聯的型別。
多載
GetTypeFromProgID(String) |
取得與指定之程式識別碼 (ProgID) 相關聯的型別,如果在載入 Type時發生錯誤,則傳回 null。 |
GetTypeFromProgID(String, Boolean) |
取得與指定之程式識別碼 (ProgID) 相關聯的型別,指定是否要在載入類型時發生錯誤時擲回例外狀況。 |
GetTypeFromProgID(String, String) |
從指定的伺服器取得與指定之程式標識碼 (progID) 相關聯的類型,如果載入類型時發生錯誤,則傳回 null。 |
GetTypeFromProgID(String, String, Boolean) |
從指定的伺服器取得與指定之程式標識碼 (progID) 相關聯的型別,指定載入類型時是否要擲回例外狀況。 |
GetTypeFromProgID(String)
- 來源:
- Type.cs
- 來源:
- Type.cs
- 來源:
- Type.cs
取得與指定之程式識別碼 (ProgID) 相關聯的型別,如果在載入 Type時發生錯誤,則傳回 null。
public:
static Type ^ GetTypeFromProgID(System::String ^ progID);
public static Type? GetTypeFromProgID (string progID);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static Type? GetTypeFromProgID (string progID);
[System.Security.SecurityCritical]
public static Type GetTypeFromProgID (string progID);
public static Type GetTypeFromProgID (string progID);
static member GetTypeFromProgID : string -> Type
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member GetTypeFromProgID : string -> Type
[<System.Security.SecurityCritical>]
static member GetTypeFromProgID : string -> Type
Public Shared Function GetTypeFromProgID (progID As String) As Type
參數
- progID
- String
要取得之型別的 ProgID。
傳回
如果 progID
是登錄中的有效專案,且類型與它相關聯,則為與指定 ProgID 相關聯的類型;否則,null
。
- 屬性
例外狀況
progID
null
。
備註
為 COM 支援提供這個方法。 ProgID 不會用於Microsoft .NET Framework 中,因為它們已被命名空間概念取代。
另請參閱
適用於
GetTypeFromProgID(String, Boolean)
- 來源:
- Type.cs
- 來源:
- Type.cs
- 來源:
- Type.cs
取得與指定之程式識別碼 (ProgID) 相關聯的型別,指定是否要在載入類型時發生錯誤時擲回例外狀況。
public:
static Type ^ GetTypeFromProgID(System::String ^ progID, bool throwOnError);
public static Type? GetTypeFromProgID (string progID, bool throwOnError);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static Type? GetTypeFromProgID (string progID, bool throwOnError);
[System.Security.SecurityCritical]
public static Type GetTypeFromProgID (string progID, bool throwOnError);
public static Type GetTypeFromProgID (string progID, bool throwOnError);
static member GetTypeFromProgID : string * bool -> Type
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member GetTypeFromProgID : string * bool -> Type
[<System.Security.SecurityCritical>]
static member GetTypeFromProgID : string * bool -> Type
Public Shared Function GetTypeFromProgID (progID As String, throwOnError As Boolean) As Type
參數
- progID
- String
要取得之型別的 ProgID。
傳回
如果 progID
是登錄中的有效專案,且類型與它相關聯,則為與指定之程式標識碼 (ProgID) 相關聯的類型;否則,null
。
- 屬性
例外狀況
progID
null
。
未註冊指定的 ProgID。
範例
下列範例會藉由傳遞 ProgID 來擷取類型,指定如果 ProgID 無效,是否擲回例外狀況。 然後,此範例會顯示與 ProgID 相關的 ClassID,以及任何適用的例外狀況訊息。
using namespace System;
int main()
{
try
{
// Use the ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1.
String^ myString1 = "DIRECT.ddPalette.3";
// Use a nonexistent ProgID WrongProgID.
String^ myString2 = "WrongProgID";
// Make a call to the method to get the type information of the given ProgID.
Type^ myType1 = Type::GetTypeFromProgID( myString1, true );
Console::WriteLine( "GUID for ProgID DirControl.DirList.1 is {0}.", myType1->GUID );
// Throw an exception because the ProgID is invalid and the throwOnError
// parameter is set to True.
Type^ myType2 = Type::GetTypeFromProgID( myString2, true );
}
catch ( Exception^ e )
{
Console::WriteLine( "An exception occurred." );
Console::WriteLine( "Source: {0}", e->Source );
Console::WriteLine( "Message: {0}", e->Message );
}
}
using System;
class MainApp
{
public static void Main()
{
try
{
// Use the ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1.
string myString1 ="DIRECT.ddPalette.3";
// Use a nonexistent ProgID WrongProgID.
string myString2 ="WrongProgID";
// Make a call to the method to get the type information of the given ProgID.
Type myType1 =Type.GetTypeFromProgID(myString1,true);
Console.WriteLine("GUID for ProgID DirControl.DirList.1 is {0}.", myType1.GUID);
// Throw an exception because the ProgID is invalid and the throwOnError
// parameter is set to True.
Type myType2 =Type.GetTypeFromProgID(myString2,true);
}
catch(Exception e)
{
Console.WriteLine("An exception occurred.");
Console.WriteLine("Source: {0}", e.Source);
Console.WriteLine("Message: {0}", e.Message);
}
}
}
open System
try
// Use the ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1.
let myString1 ="DIRECT.ddPalette.3"
// Use a nonexistent ProgID WrongProgID.
let myString2 ="WrongProgID"
// Make a call to the method to get the type information of the given ProgID.
let myType1 =Type.GetTypeFromProgID(myString1, true)
printfn $"GUID for ProgID DirControl.DirList.1 is {myType1.GUID}."
// Throw an exception because the ProgID is invalid and the throwOnError
// parameter is set to True.
let myType2 =Type.GetTypeFromProgID(myString2, true)
()
with e ->
printfn "An exception occurred."
printfn $"Source: {e.Source}"
printfn $"Message: {e.Message}"
Class MainApp
Public Shared Sub Main()
Try
' Use the ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1.
Dim myString1 As String = "DIRECT.ddPalette.3"
' Use a nonexistent ProgID WrongProgID.
Dim myString2 As String = "WrongProgID"
' Make a call to the method to get the type information of the given ProgID.
Dim myType1 As Type = Type.GetTypeFromProgID(myString1, True)
Console.WriteLine("GUID for ProgID DirControl.DirList.1 is {0}.", myType1.GUID.ToString())
' Throw an exception because the ProgID is invalid and the throwOnError
' parameter is set to True.
Dim myType2 As Type = Type.GetTypeFromProgID(myString2, True)
Catch e As Exception
Console.WriteLine("An exception occurred.")
Console.WriteLine("Source: {0}", e.Source.ToString())
Console.WriteLine("Message: {0}", e.Message.ToString())
End Try
End Sub
End Class
備註
為 COM 支援提供這個方法。 程序標識碼不會用於Microsoft .NET Framework,因為它們已被命名空間概念取代。
另請參閱
適用於
GetTypeFromProgID(String, String)
- 來源:
- Type.cs
- 來源:
- Type.cs
- 來源:
- Type.cs
從指定的伺服器取得與指定之程式標識碼 (progID) 相關聯的類型,如果載入類型時發生錯誤,則傳回 null。
public:
static Type ^ GetTypeFromProgID(System::String ^ progID, System::String ^ server);
public static Type? GetTypeFromProgID (string progID, string? server);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static Type? GetTypeFromProgID (string progID, string? server);
[System.Security.SecurityCritical]
public static Type GetTypeFromProgID (string progID, string server);
public static Type GetTypeFromProgID (string progID, string server);
static member GetTypeFromProgID : string * string -> Type
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member GetTypeFromProgID : string * string -> Type
[<System.Security.SecurityCritical>]
static member GetTypeFromProgID : string * string -> Type
Public Shared Function GetTypeFromProgID (progID As String, server As String) As Type
參數
- progID
- String
要取得之型別的 progID。
- server
- String
要從中載入型別的伺服器。 如果伺服器名稱 null
,這個方法會自動還原為本機計算機。
傳回
如果 progID
是登錄中的有效專案,且類型與它相關聯,則為與指定之程式標識碼 (progID) 相關聯的類型;否則,null
。
- 屬性
例外狀況
progID
null
。
範例
下列範例會藉由傳遞 ProgID 和伺服器名稱來擷取類型。 然後,此範例會顯示與 ProgID 相關的 ClassID,如果 ProgID 或伺服器名稱無效,則會擲回例外狀況。
using namespace System;
int main()
{
try
{
// Use the ProgID localhost\HKEY_CLASSES_ROOT\DirControl::DirList.1.
String^ theProgramID = "DirControl.DirList.1";
// Use the server name localhost.
String^ theServer = "localhost";
// Make a call to the method to get the type information for the given ProgID.
Type^ myType = Type::GetTypeFromProgID( theProgramID, theServer );
if ( myType == nullptr )
{
throw gcnew Exception( "Invalid ProgID or Server." );
}
Console::WriteLine( "GUID for ProgID DirControl.DirList.1 is {0}.", myType->GUID );
}
catch ( Exception^ e )
{
Console::WriteLine( "An exception occurred." );
Console::WriteLine( "Source: {0}", e->Source );
Console::WriteLine( "Message: {0}", e->Message );
}
}
using System;
class MainApp
{
public static void Main()
{
try
{
// Use the ProgID localhost\HKEY_CLASSES_ROOT\DirControl.DirList.1.
string theProgramID ="DirControl.DirList.1";
// Use the server name localhost.
string theServer="localhost";
// Make a call to the method to get the type information for the given ProgID.
Type myType =Type.GetTypeFromProgID(theProgramID,theServer);
if(myType==null)
{
throw new Exception("Invalid ProgID or Server.");
}
Console.WriteLine("GUID for ProgID DirControl.DirList.1 is {0}.", myType.GUID);
}
catch(Exception e)
{
Console.WriteLine("An exception occurred.");
Console.WriteLine("Source: {0}" , e.Source);
Console.WriteLine("Message: {0}" , e.Message);
}
}
}
open System
try
// Use the ProgID localhost\HKEY_CLASSES_ROOT\DirControl.DirList.1.
let theProgramID ="DirControl.DirList.1"
// Use the server name localhost.
let theServer="localhost"
// Make a call to the method to get the type information for the given ProgID.
let myType =Type.GetTypeFromProgID(theProgramID, theServer)
if myType = null then
raise (Exception "Invalid ProgID or Server.")
printfn $"GUID for ProgID DirControl.DirList.1 is {myType.GUID}."
with e ->
printfn "An exception occurred."
printfn $"Source: {e.Source}"
printfn $"Message: {e.Message}"
Class MainApp
Public Shared Sub Main()
Try
' Use ProgID localhost\HKEY_CLASSES_ROOT\DirControl.DirList.1.
Dim theProgramID As String = "DirControl.DirList.1"
' Use Server name localhost.
Dim theServer As String = "localhost"
' Make a call to the method to get the type information for the given ProgID.
Dim myType As Type = Type.GetTypeFromProgID(theProgramID, theServer)
If myType Is Nothing Then
Throw New Exception("Invalid ProgID or server.")
End If
Console.WriteLine("GUID for ProgID DirControl.DirList.1 is {0}.", myType.GUID.ToString())
Catch e As Exception
Console.WriteLine("An exception occurred.")
Console.WriteLine("Source: {0}.", e.Source.ToString())
Console.WriteLine("Message: {0}.", e.Message.ToString())
End Try
End Sub
End Class
備註
為 COM 支援提供這個方法。 程序標識碼不會用於Microsoft .NET Framework,因為它們已被命名空間概念取代。
另請參閱
適用於
GetTypeFromProgID(String, String, Boolean)
- 來源:
- Type.cs
- 來源:
- Type.cs
- 來源:
- Type.cs
從指定的伺服器取得與指定之程式標識碼 (progID) 相關聯的型別,指定載入類型時是否要擲回例外狀況。
public:
static Type ^ GetTypeFromProgID(System::String ^ progID, System::String ^ server, bool throwOnError);
public static Type? GetTypeFromProgID (string progID, string? server, bool throwOnError);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static Type? GetTypeFromProgID (string progID, string? server, bool throwOnError);
[System.Security.SecurityCritical]
public static Type GetTypeFromProgID (string progID, string server, bool throwOnError);
public static Type GetTypeFromProgID (string progID, string server, bool throwOnError);
static member GetTypeFromProgID : string * string * bool -> Type
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member GetTypeFromProgID : string * string * bool -> Type
[<System.Security.SecurityCritical>]
static member GetTypeFromProgID : string * string * bool -> Type
Public Shared Function GetTypeFromProgID (progID As String, server As String, throwOnError As Boolean) As Type
參數
- server
- String
要從中載入型別的伺服器。 如果伺服器名稱 null
,這個方法會自動還原為本機計算機。
傳回
如果 progID
是登錄中的有效專案,且類型與它相關聯,則為與指定之程式標識碼 (progID) 相關聯的類型;否則,null
。
- 屬性
例外狀況
progID
null
。
未註冊指定的 progID。
範例
下列範例會藉由傳遞 ProgID 和伺服器名稱來擷取類型。 然後,此範例會顯示與 ProgID 相關的 ClassID,指定如果 ProgID 或伺服器名稱無效,是否擲回例外狀況。
using namespace System;
int main()
{
try
{
// Use server localhost.
String^ theServer = "localhost";
// Use ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1.
String^ myString1 = "DirControl.DirList.1";
// Use a wrong ProgID WrongProgID.
String^ myString2 = "WrongProgID";
// Make a call to the method to get the type information for the given ProgID.
Type^ myType1 = Type::GetTypeFromProgID( myString1, theServer, true );
Console::WriteLine( "GUID for ProgID DirControl.DirList.1 is {0}.", myType1->GUID );
// Throw an exception because the ProgID is invalid and the throwOnError
// parameter is set to True.
Type^ myType2 = Type::GetTypeFromProgID( myString2, theServer, true );
}
catch ( Exception^ e )
{
Console::WriteLine( "An exception occurred. The ProgID is wrong." );
Console::WriteLine( "Source: {0}", e->Source );
Console::WriteLine( "Message: {0}", e->Message );
}
}
using System;
class MainApp
{
public static void Main()
{
try
{
// Use server localhost.
string theServer="localhost";
// Use ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1.
string myString1 ="DirControl.DirList.1";
// Use a wrong ProgID WrongProgID.
string myString2 ="WrongProgID";
// Make a call to the method to get the type information for the given ProgID.
Type myType1 =Type.GetTypeFromProgID(myString1,theServer,true);
Console.WriteLine("GUID for ProgID DirControl.DirList.1 is {0}.", myType1.GUID);
// Throw an exception because the ProgID is invalid and the throwOnError
// parameter is set to True.
Type myType2 =Type.GetTypeFromProgID(myString2, theServer, true);
}
catch(Exception e)
{
Console.WriteLine("An exception occurred. The ProgID is wrong.");
Console.WriteLine("Source: {0}" , e.Source);
Console.WriteLine("Message: {0}" , e.Message);
}
}
}
open System
try
// Use server localhost.
let theServer="localhost"
// Use ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1.
let myString1 ="DirControl.DirList.1"
// Use a wrong ProgID WrongProgID.
let myString2 ="WrongProgID"
// Make a call to the method to get the type information for the given ProgID.
let myType1 =Type.GetTypeFromProgID(myString1, theServer, true)
printfn $"GUID for ProgID DirControl.DirList.1 is {myType1.GUID}."
// Throw an exception because the ProgID is invalid and the throwOnError
// parameter is set to True.
let myType2 =Type.GetTypeFromProgID(myString2, theServer, true)
()
with e ->
printfn "An exception occurred. The ProgID is wrong."
printfn $"Source: {e.Source}"
printfn $"Message: {e.Message}"
Class MainApp
Public Shared Sub Main()
Try
' Use Server localhost.
Dim theServer As String = "localhost"
' Use ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1.
Dim myString1 As String = "DirControl.DirList.1"
' Use a wrong ProgID WrongProgID.
Dim myString2 As String = "WrongProgID"
' Make a call to the method to get the type information for the given ProgID.
Dim myType1 As Type = Type.GetTypeFromProgID(myString1, theServer, True)
Console.WriteLine("GUID for ProgID DirControl.DirList.1 is {0}.", myType1.GUID.ToString())
' Throw an exception because the ProgID is invalid and the throwOnError
' parameter is set to True.
Dim myType2 As Type = Type.GetTypeFromProgID(myString2, theServer, True)
Catch e As Exception
Console.WriteLine("An exception occurred. The ProgID is wrong.")
Console.WriteLine("Source: {0}", e.Source.ToString())
Console.WriteLine("Message: {0}", e.Message.ToString())
End Try
End Sub
End Class
備註
為 COM 支援提供這個方法。 程序標識碼不會用於Microsoft .NET Framework,因為它們已被命名空間概念取代。