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.
Module::GetCustomAttributes Method (Type^, Boolean)
.NET Framework (current version)
Gets custom attributes of the specified type.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- attributeType
-
Type:
System::Type^
The type of attribute to get.
- inherit
-
Type:
System::Boolean
This argument is ignored for objects of this type.
Return Value
Type: array<System::Object^>^An array of type Object containing all custom attributes of the specified type.
| Exception | Condition |
|---|---|
| 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 displays the module names of the specified type that match the specified search criteria.
using namespace System; using namespace System::Reflection; using namespace System::Collections; namespace ReflectionModule_Examples { // Define a very simple custom attribute [AttributeUsage(AttributeTargets::Class|AttributeTargets::Module)] public ref class MySimpleAttribute: public Attribute { private: String^ name; public: MySimpleAttribute( String^ newName ) { name = newName; } }; } //Define a module-level attribute. [module:ReflectionModule_Examples::MySimpleAttribute("module-level")]; int main() { array<System::Reflection::Module^>^moduleArray; moduleArray = ReflectionModule_Examples::MySimpleAttribute::typeid->Assembly->GetModules( false ); // In a simple project with only one module, the module at index // 0 will be the module containing these classes. System::Reflection::Module^ myModule = moduleArray[ 0 ]; array<Object^>^attributes; //Get only MySimpleAttribute attributes for this module. attributes = myModule->GetCustomAttributes( myModule->GetType( "ReflectionModule_Examples.MySimpleAttribute", false, false ), true ); IEnumerator^ myEnum = attributes->GetEnumerator(); while ( myEnum->MoveNext() ) { Object^ o = safe_cast<Object^>(myEnum->Current); Console::WriteLine( "Found this attribute on myModule: {0}", o ); } }
.NET Framework
Available since 1.1
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 1.1
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Show: