Attribute.GetCustomAttributes 方法 (Assembly, Boolean)
.NET Framework 4.5
命名空间: System
程序集: mscorlib(在 mscorlib.dll 中)
参数
- element
- 类型:System.Reflection.Assembly
一个从 Assembly 类派生的对象,该类描述可重用模块集合。
- inherit
- 类型:System.Boolean
此参数被忽略,并且不会影响此方法的操作。
| 异常 | 条件 |
|---|---|
| ArgumentNullException |
说明 |
|---|
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(不支持服务器核心角色), Windows Server 2008 R2(支持带 SP1 或更高版本的服务器核心角色;不支持 Itanium)
.NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。
说明