Assembly.IsDefined Method

Indicates whether or not a specified attribute has been applied to the assembly.

Namespace:  System.Reflection
Assembly:  mscorlib (in mscorlib.dll)

public virtual bool IsDefined(
	Type attributeType,
	bool inherit
)

Parameters

attributeType
Type: System.Type
The Type of the attribute to be checked for this assembly.
inherit
Type: System.Boolean
This argument is ignored for objects of this type.

Return Value

Type: System.Boolean
true if the attribute has been applied to the assembly; otherwise, false.

Implements

ICustomAttributeProvider.IsDefined(Type, Boolean)

ExceptionCondition
ArgumentNullException

attributeType is null.

ArgumentException

attributeType uses an invalid type.

The following code example applies the AssemblyTitleAttribute attribute to an assembly and then uses IsDefined to indicate whether it was applied. It also tests an attribute that was not applied.


using System;
using System.Reflection;

//Apply an assembly-level attribute.
[assembly: AssemblyTitleAttribute("My Cool Application")]

class Example
{
    public static void Demo(System.Windows.Controls.TextBlock outputBlock)
    {
        Assembly thisAssembly = Assembly.GetExecutingAssembly();
        outputBlock.Text += 
            String.Format("IsDefined(AssemblyTitleAttribute) = {0}\n", 
                          thisAssembly.IsDefined(typeof(AssemblyTitleAttribute), false));
        outputBlock.Text += 
            String.Format("IsDefined(AssemblyCompanyAttribute) = {0}\n", 
                          thisAssembly.IsDefined(typeof(AssemblyCompanyAttribute), false));
    }
}

/* This example produces output similar to the following:

IsDefined(AssemblyTitleAttribute) = True
IsDefined(AssemblyCompanyAttribute) = False
 */


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show: