Determines whether any custom attributes are applied to an assembly.
using System;
using System.Reflection;
[assembly: AssemblyDescription("A sample description")]
public class DemoClass
{
static void Main(string[] args)
{
Type clsType = typeof(DemoClass);
Assembly assy = clsType.Assembly;
String assyName = assy.GetName().Name;
bool isdef = Attribute.IsDefined(assy, typeof(AssemblyDescriptionAttribute));
if (isdef)
{
Console.WriteLine("The AssemblyDescription attribute is defined for assembly {0}.", assyName);
AssemblyDescriptionAttribute adAttr = (AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(assy, typeof(AssemblyDescriptionAttribute));
if (adAttr != null)
Console.WriteLine("The description is \"{0}\".", adAttr.Description);
}
}
}
Related examples in the same category