Cet article a fait l'objet d'une traduction manuelle. Déplacez votre pointeur sur les phrases de l'article pour voir la version originale de ce texte. |
Traduction
Source
|
Type.GetTypeFromProgID, méthode (String, String, Boolean)
Obtient le type associé à l'identificateur de programme (ProgID) spécifié à partir du serveur défini, indiquant s'il faut lever une exception en cas d'erreur pendant le chargement du type.
Assembly : mscorlib (dans mscorlib.dll)
public static Type GetTypeFromProgID( string progID, string server, bool throwOnError )
Paramètres
- progID
- Type : System.String
PROGID du Type à obtenir.
- server
- Type : System.String
Serveur à partir duquel le type doit être chargé. Si le nom de serveur est null, cette méthode revient automatiquement à la machine locale.
- throwOnError
- Type : System.Boolean
true pour lever toute exception qui se produit.
ou
false pour ignorer toute exception qui se produit.
Valeur de retour
Type : System.TypeType associé à l'identificateur de programme (ProgID) spécifié si progID est une entrée valide dans le Registre et qu'un type lui est associé ; sinon, null.
| Exception | Condition |
|---|---|
| ArgumentException |
progID est null. |
| COMException |
L'identificateur de programme (progID) spécifié n'est pas inscrit. |
L'exemple suivant récupère un type en passant un identificateur de programme (ProgID) et un nom de serveur. Il affiche ensuite le ClassID associé au ProgID, en indiquant s'il faut lever une exception si le ProgID ou le nom de serveur n'est pas valide.
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); } } }
-
SecurityCriticalAttribute
exige une confiance totale pour l'appelant immédiat. Ce membre ne peut pas être utilisé par du code partiellement de confiance ou transparent.
Windows 7, Windows Vista SP1 ou ultérieur, Windows XP SP3, Windows XP SP2 Édition x64, Windows Server 2008 (installation minimale non prise en charge), Windows Server 2008 R2 (installation minimale prise en charge avec SP1 ou version ultérieure), Windows Server 2003 SP2
Le .NET Framework ne prend pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.