CSharp · Console
// C# Extension Method
// Doc: https://csharp-extension.com/en/method/1002804/assembly-getcustomattributes
// @nuget: Z.ExtensionMethods
using System;
using System.Reflection;
[assembly: AssemblyTitle("CustAttrs1CS")]
[assembly: AssemblyDescription("GetCustomAttributes() Demo")]
[assembly: AssemblyCompany("ZZZ Projects")]
namespace ExtensionMethods
{
public class Program
{
public static void Main()
{
Assembly assy = typeof(Program).Assembly;
//C# Extension Method: Assembly - GetCustomAttributes
foreach (Attribute attr in Attribute.GetCustomAttributes(assy))
{
if (attr.GetType() == typeof(AssemblyTitleAttribute))
Console.WriteLine("Assembly title is \"{0}\".", ((AssemblyTitleAttribute)attr).Title);
else if (attr.GetType() == typeof(AssemblyDescriptionAttribute))
Console.WriteLine("Assembly description is \"{0}\".", ((AssemblyDescriptionAttribute)attr).Description);
else if (attr.GetType() == typeof(AssemblyCompanyAttribute))
Console.WriteLine("Assembly company is {0}.", ((AssemblyCompanyAttribute)attr).Company);
}
}
}
}