Assembly.IsDefined Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

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

Syntax

'Declaration
Public Overridable Function IsDefined ( _
    attributeType As Type, _
    inherit As Boolean _
) As Boolean
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)

Exceptions

Exception Condition
ArgumentNullException

attributeType is nulla null reference (Nothing in Visual Basic).

ArgumentException

attributeType uses an invalid type.

Examples

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.

Imports System.Reflection

' Apply an assembly-level attribute.
<Assembly: AssemblyTitleAttribute("My Cool Application")> 

Class Example
    Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
        Dim thisAssembly As [Assembly] = [Assembly].GetExecutingAssembly()
        outputBlock.Text &= _
            String.Format("IsDefined(AssemblyTitleAttribute) = {0}" & vbLf, _
                          thisAssembly.IsDefined(GetType(AssemblyTitleAttribute), False))
        outputBlock.Text &= _
            String.Format("IsDefined(AssemblyCompanyAttribute) = {0}" & vbLf, _
                          thisAssembly.IsDefined(GetType(AssemblyCompanyAttribute), False))
    End Sub 
End Class 

' This example produces output similar to the following:
'
'IsDefined(AssemblyTitleAttribute) = True
'IsDefined(AssemblyCompanyAttribute) = False
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
 */

Version Information

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

Platforms

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