Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Attribute::IsDefined Method (Module^, Type^, Boolean)

 

Determines whether any custom attributes are applied to a module. Parameters specify the module, the type of the custom attribute to search for, and an ignored search option.

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

public:
static bool IsDefined(
	Module^ element,
	Type^ attributeType,
	bool inherit
)

Parameters

element
Type: System.Reflection::Module^

An object derived from the Module class that describes a portable executable file.

attributeType
Type: System::Type^

The type, or a base type, of the custom attribute to search for.

inherit
Type: System::Boolean

This parameter is ignored, and does not affect the operation of this method.

Return Value

Type: System::Boolean

true if a custom attribute of type attributeType is applied to element; otherwise, false.

Exception Condition
ArgumentNullException

element or attributeType is null.

ArgumentException

attributeType is not derived from Attribute.

This method ignores the inherit parameter and does not search the ancestors of element for custom attributes.

The following code example illustrates the use of IsDefined, taking a Module as a parameter.

using namespace System;
using namespace System::Diagnostics;

// Add the Debuggable attribute to the module.
[module:Debuggable(true,false)];
namespace IsDef2CS
{
   ref class DemoClass
   {
   public:
      static void Main()
      {

         // Get the class type to access its metadata.
         Type^ clsType = DemoClass::typeid;

         // See if the Debuggable attribute is defined for this module.
         bool isDef = Attribute::IsDefined( clsType->Module, DebuggableAttribute::typeid );

         // Display the result.
         Console::WriteLine( "The Debuggable attribute {0} "
         "defined for Module {1}.", isDef ? (String^)"is" : "is not", clsType->Module->Name );

         // If the attribute is defined, display the JIT settings.
         if ( isDef )
         {

            // Retrieve the attribute itself.
            DebuggableAttribute^ dbgAttr = dynamic_cast<DebuggableAttribute^>(Attribute::GetCustomAttribute( clsType->Module, DebuggableAttribute::typeid ));
            if ( dbgAttr != nullptr )
            {
               Console::WriteLine( "JITTrackingEnabled is {0}.", dbgAttr->IsJITTrackingEnabled );
               Console::WriteLine( "JITOptimizerDisabled is {0}.", dbgAttr->IsJITOptimizerDisabled );
            }
            else
                        Console::WriteLine( "The Debuggable attribute "
            "could not be retrieved." );
         }
      }

   };

}


/*
 * Output:
 * The Debuggable attribute is defined for Module IsDef2CS.exe.
 * JITTrackingEnabled is True.
 * JITOptimizerDisabled is False.
 */

.NET Framework
Available since 1.1
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
Show: