|
Cet article a fait l'objet d'une traduction automatique. Déplacez votre pointeur sur les phrases de l'article pour voir la version originale de ce texte. Informations supplémentaires.
|
Traduction
Source
|
Attribute.GetCustomAttributes, méthode (Assembly, Boolean)
Espace de noms : System
Assembly : mscorlib (dans mscorlib.dll)
Paramètres
- element
- Type : System.Reflection.Assembly
Objet dérivé de la classe Assembly qui décrit une collection de modules réutilisable.
- inherit
- Type : System.Boolean
Ce paramètre est ignoré, mais cela n'affecte pas le fonctionnement de cette méthode.
Valeur de retour
Type : System.Attribute[]| Exception | Condition |
|---|---|
| ArgumentNullException |
Remarque |
|---|
using System; using System.Reflection; [assembly: AssemblyTitle("CustAttrs1CS")] [assembly: AssemblyDescription("GetCustomAttributes() Demo")] [assembly: AssemblyCompany("Microsoft")] namespace CustAttrs1CS { class DemoClass { static void Main(string[] args) { Type clsType = typeof(DemoClass); // Get the Assembly type to access its metadata. Assembly assy = clsType.Assembly; // Iterate through the attributes for the assembly. foreach(Attribute attr in Attribute.GetCustomAttributes(assy)) { // Check for the AssemblyTitle attribute. if (attr.GetType() == typeof(AssemblyTitleAttribute)) Console.WriteLine("Assembly title is \"{0}\".", ((AssemblyTitleAttribute)attr).Title); // Check for the AssemblyDescription attribute. else if (attr.GetType() == typeof(AssemblyDescriptionAttribute)) Console.WriteLine("Assembly description is \"{0}\".", ((AssemblyDescriptionAttribute)attr).Description); // Check for the AssemblyCompany attribute. else if (attr.GetType() == typeof(AssemblyCompanyAttribute)) Console.WriteLine("Assembly company is {0}.", ((AssemblyCompanyAttribute)attr).Company); } } } } /* * Output: * Assembly company is Microsoft. * Assembly description is "GetCustomAttributes() Demo". * Assembly title is "CustAttrs1CS". */
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (rôle principal du serveur non pris en charge), Windows Server 2008 R2 (rôle principal du serveur pris en charge avec SP1 ou version ultérieure ; Itanium non pris en charge)
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.
Remarque