Lire en anglais

Partager via


Type.GetTypeFromProgID Méthode

Définition

Obtient le type associé à l’identificateur de programme spécifié (ProgID).

Surcharges

GetTypeFromProgID(String)

Obtient le type associé à l’identificateur de programme spécifié (ProgID), en retournant null si une erreur est rencontrée lors du chargement du Type.

GetTypeFromProgID(String, Boolean)

Obtient le type associé à l’identificateur de programme spécifié (ProgID), en spécifiant s’il faut lever une exception si une erreur se produit lors du chargement du type.

GetTypeFromProgID(String, String)

Obtient le type associé à l’identificateur de programme spécifié (progID) à partir du serveur spécifié, en retournant null si une erreur est rencontrée lors du chargement du type.

GetTypeFromProgID(String, String, Boolean)

Obtient le type associé à l’identificateur de programme spécifié (progID) à partir du serveur spécifié, en spécifiant s’il faut lever une exception si une erreur se produit lors du chargement du type.

GetTypeFromProgID(String)

Source:
Type.cs
Source:
Type.cs
Source:
Type.cs

Obtient le type associé à l’identificateur de programme spécifié (ProgID), en retournant null si une erreur est rencontrée lors du chargement du Type.

C#
public static Type? GetTypeFromProgID (string progID);
C#
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static Type? GetTypeFromProgID (string progID);
C#
[System.Security.SecurityCritical]
public static Type GetTypeFromProgID (string progID);
C#
public static Type GetTypeFromProgID (string progID);

Paramètres

progID
String

ProgID du type à obtenir.

Retours

Type associé au ProgID spécifié, si progID est une entrée valide dans le Registre et qu’un type est associé à celui-ci ; sinon, null.

Attributs

Exceptions

progID est null.

Remarques

Cette méthode est fournie pour la prise en charge COM. Les progID ne sont pas utilisés dans Microsoft .NET Framework, car ils ont été remplacés par le concept d’espace de noms.

Voir aussi

S’applique à

.NET 9 et autres versions
Produit Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.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

GetTypeFromProgID(String, Boolean)

Source:
Type.cs
Source:
Type.cs
Source:
Type.cs

Obtient le type associé à l’identificateur de programme spécifié (ProgID), en spécifiant s’il faut lever une exception si une erreur se produit lors du chargement du type.

C#
public static Type? GetTypeFromProgID (string progID, bool throwOnError);
C#
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static Type? GetTypeFromProgID (string progID, bool throwOnError);
C#
[System.Security.SecurityCritical]
public static Type GetTypeFromProgID (string progID, bool throwOnError);
C#
public static Type GetTypeFromProgID (string progID, bool throwOnError);

Paramètres

progID
String

ProgID du type à obtenir.

throwOnError
Boolean

true lever toute exception qui se produit.

-ou-

false pour ignorer toute exception qui se produit.

Retours

Type associé à l’identificateur de programme spécifié (ProgID), si progID est une entrée valide dans le Registre et qu’un type lui est associé ; sinon, null.

Attributs

Exceptions

progID est null.

Le ProgID spécifié n’est pas inscrit.

Exemples

L’exemple suivant récupère un type en passant un ProgID, en spécifiant s’il faut lever une exception si le ProgID n’est pas valide. L’exemple affiche ensuite l’ID de classe associé au ProgID, ainsi que tout message d’exception applicable.

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

Remarques

Cette méthode est fournie pour la prise en charge COM. Les ID de programme ne sont pas utilisés dans Microsoft .NET Framework, car ils ont été remplacés par le concept d’espace de noms.

Voir aussi

S’applique à

.NET 9 et autres versions
Produit Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.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

GetTypeFromProgID(String, String)

Source:
Type.cs
Source:
Type.cs
Source:
Type.cs

Obtient le type associé à l’identificateur de programme spécifié (progID) à partir du serveur spécifié, en retournant null si une erreur est rencontrée lors du chargement du type.

C#
public static Type? GetTypeFromProgID (string progID, string? server);
C#
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static Type? GetTypeFromProgID (string progID, string? server);
C#
[System.Security.SecurityCritical]
public static Type GetTypeFromProgID (string progID, string server);
C#
public static Type GetTypeFromProgID (string progID, string server);

Paramètres

progID
String

ProgID du type à obtenir.

server
String

Serveur à partir duquel charger le type. Si le nom du serveur est null, cette méthode revient automatiquement à l’ordinateur local.

Retours

Type associé à l’identificateur de programme spécifié (progID), si progID est une entrée valide dans le Registre et qu’un type est associé à celui-ci ; sinon, null.

Attributs

Exceptions

progID est null.

Exemples

L’exemple suivant récupère un type en passant un ProgID et un nom de serveur. L’exemple affiche ensuite l’ID de classe lié au ProgID ou lève une exception si progID ou le nom du serveur n’est pas valide.

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

Remarques

Cette méthode est fournie pour la prise en charge COM. Les ID de programme ne sont pas utilisés dans Microsoft .NET Framework, car ils ont été remplacés par le concept d’espace de noms.

Voir aussi

S’applique à

.NET 9 et autres versions
Produit Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.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

GetTypeFromProgID(String, String, Boolean)

Source:
Type.cs
Source:
Type.cs
Source:
Type.cs

Obtient le type associé à l’identificateur de programme spécifié (progID) à partir du serveur spécifié, en spécifiant s’il faut lever une exception si une erreur se produit lors du chargement du type.

C#
public static Type? GetTypeFromProgID (string progID, string? server, bool throwOnError);
C#
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static Type? GetTypeFromProgID (string progID, string? server, bool throwOnError);
C#
[System.Security.SecurityCritical]
public static Type GetTypeFromProgID (string progID, string server, bool throwOnError);
C#
public static Type GetTypeFromProgID (string progID, string server, bool throwOnError);

Paramètres

progID
String

ProgID du Type à obtenir.

server
String

Serveur à partir duquel charger le type. Si le nom du serveur est null, cette méthode revient automatiquement à l’ordinateur local.

throwOnError
Boolean

true lever toute exception qui se produit.

-ou-

false pour ignorer toute exception qui se produit.

Retours

Type associé à l’identificateur de programme spécifié (progID), si progID est une entrée valide dans le Registre et qu’un type est associé à celui-ci ; sinon, null.

Attributs

Exceptions

progID est null.

Le progID spécifié n’est pas inscrit.

Exemples

L’exemple suivant récupère un type en passant un ProgID et un nom de serveur. L’exemple affiche ensuite l’ID de classe lié au ProgID, en spécifiant s’il faut lever une exception si progID ou le nom du serveur n’est pas valide.

C#

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

Remarques

Cette méthode est fournie pour la prise en charge COM. Les ID de programme ne sont pas utilisés dans Microsoft .NET Framework, car ils ont été remplacés par le concept d’espace de noms.

Voir aussi

S’applique à

.NET 9 et autres versions
Produit Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.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