Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
IsDefined Method

Module.IsDefined Method

Determines if the specified attribute type is applied to this module.

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

public virtual bool IsDefined(
	Type attributeType,
	bool inherit
)

Parameters

attributeType
Type: System.Type
The type of custom attribute to search for.
inherit
Type: System.Boolean
This argument is ignored for objects of this type.

Return Value

Type: System.Boolean
true if one or more instances of attributeType are applied to this module; otherwise, false.

Implements

ICustomAttributeProvider.IsDefined(Type, Boolean)

ExceptionCondition
ArgumentNullException

attributeType is null.

ArgumentException

attributeType is not a Type object supplied by the runtime. For example, attributeType is a TypeBuilder object.

The following example defines an attribute, applies it to the example's module , and uses the IsDefined method to show that the attribute was applied to the module.


using System;
using System.Reflection;

//Define a module-level attribute.
[module: MySimpleAttribute("module-level")]

class Example
{
    public static void Demo(System.Windows.Controls.TextBlock outputBlock)
    {
        Module[] moduleArray = Assembly.GetExecutingAssembly().GetModules();
        Module myModule = moduleArray[0];
        outputBlock.Text += 
            String.Format("IsDefined(MySimpleAttribute) = {0}\n", 
                          myModule.IsDefined(typeof(MySimpleAttribute), false));
    }
}

//A very simple custom attribute.
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Module)]
public class MySimpleAttribute : Attribute
{
    private string name;

    public MySimpleAttribute(string newName)
    {
        name = newName;
    }
}

/* This example produces output similar to the following:

IsDefined(MySimpleAttribute) = True
 */


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:
© 2015 Microsoft