IsDefined Method

Assembly.IsDefined Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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
 */


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2016 Microsoft