Module.GetCustomAttributes メソッド (Type, Boolean)
アセンブリ: mscorlib (mscorlib.dll 内)

Public Overridable Function GetCustomAttributes ( _ attributeType As Type, _ inherit As Boolean _ ) As Object()
Dim instance As Module Dim attributeType As Type Dim inherit As Boolean Dim returnValue As Object() returnValue = instance.GetCustomAttributes(attributeType, inherit)
戻り値
指定された型のすべてのカスタム属性を格納しているオブジェクト型の配列。


指定した型で、指定した検索条件と一致するモジュールの名前を表示する例を次に示します。
Imports System Imports System.Reflection ' Define a module-level attribute. <Module: ReflectionModule_Examples.MySimpleAttribute("module-level")> ' This code assumes that the root namespace is set to empty(""). Namespace ReflectionModule_Examples Class MyMainClass Shared Sub Main() Dim moduleArray() As [Module] moduleArray = [Assembly].GetExecutingAssembly().GetModules(False) ' In a simple project with only one module, the module at index ' 0 will be the module containing these classes. Dim myModule As [Module] = moduleArray(0) Dim attributes() As Object ' Get only MySimpleAttribute attributes for this module. attributes = myModule.GetCustomAttributes( _ myModule.GetType("ReflectionModule_Examples.MySimpleAttribute", _ False, False), True) Dim o As [Object] For Each o In attributes Console.WriteLine("Found this attribute on myModule: {0}", o.ToString()) Next o End Sub 'Main End Class 'MyMainClass ' Define a very simple custom attribute. <AttributeUsage(AttributeTargets.Class Or AttributeTargets.Module)> _ Public Class MySimpleAttribute Inherits Attribute Private name As String Public Sub New(ByVal newName As String) name = newName End Sub 'New End Class 'MySimpleAttribute End Namespace 'ReflectionModule_Examples
using System; using System.Reflection; //Define a module-level attribute. [module: ReflectionModule_Examples.MySimpleAttribute("module-level")] namespace ReflectionModule_Examples { class MyMainClass { static void Main() { Module[] moduleArray; moduleArray = Assembly.GetExecutingAssembly().GetModules(false); // In a simple project with only one module, the module at index // 0 will be the module containing these classes. Module myModule = moduleArray[0]; object[] attributes; //Get only MySimpleAttribute attributes for this module. attributes = myModule.GetCustomAttributes( myModule.GetType("ReflectionModule_Examples.MySimpleAttribute", false, false), true); foreach(Object o in attributes) { Console.WriteLine("Found this attribute on myModule: {0}", o.ToString()); } } } // Define a very simple custom attribute [AttributeUsage(AttributeTargets.Class | AttributeTargets.Module)] public class MySimpleAttribute : Attribute { private string name; public MySimpleAttribute(string newName) { name = newName; } } }
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 = Assembly::GetExecutingAssembly()->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 ); } }
package ReflectionModule_Examples; import System.*; import System.Reflection.*; //Define a module-level attribute. /** @module ReflectionModule_Examples.MySimpleAttribute("module-level") */ class MyMainClass { public static void main(String[] args) { Module moduleArray[]; moduleArray = Assembly.GetExecutingAssembly().GetModules(false); // In a simple project with only one module, the module at index // 0 will be the module containing these classes. Module myModule = (Module)moduleArray.get_Item(0); Object attributes[]; //Get only MySimpleAttribute attributes for this module. attributes = myModule.GetCustomAttributes( myModule.GetType("ReflectionModule_Examples.MySimpleAttribute", false, false), true); for (int iCtr = 0; iCtr < attributes.length; iCtr++) { Object o = attributes[iCtr]; Console.WriteLine("Found this attribute on myModule: {0}", o.ToString()); } } //main } //MyMainClass // Define a very simple custom attribute /** @attribute AttributeUsage(AttributeTargets.Class | AttributeTargets.Module) */ public class MySimpleAttribute extends Attribute { private String name; public MySimpleAttribute(String newName) { name = newName; } //MySimpleAttribute } //MySimpleAttribute

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Module.GetCustomAttributes メソッド

名前 | 説明 |
---|---|
Module.GetCustomAttributes (Boolean) | すべてのカスタム属性を返します。 .NET Compact Framework によってサポートされています。 |
Module.GetCustomAttributes (Type, Boolean) | 指定された型のカスタム属性を取得します。 .NET Compact Framework によってサポートされています。 |

Module.GetCustomAttributes メソッド (Boolean)
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As Module Dim inherit As Boolean Dim returnValue As Object() returnValue = instance.GetCustomAttributes(inherit)
戻り値
すべてのカスタム属性が格納されているオブジェクト型の配列。

指定した検索条件に一致するモジュール名を表示する例を次に示します。
Imports System Imports System.Reflection ' Define a module-level attribute. <Module: ReflectionModule_Examples.MySimpleAttribute("module-level")> Namespace ReflectionModule_Examples Class MyMainClass Shared Sub Main() Dim moduleArray() As [Module] moduleArray = [Assembly].GetExecutingAssembly().GetModules(False) ' In a simple project with only one module, the module at index ' 0 will be the module containing these classes. Dim myModule As [Module] = moduleArray(0) Dim attributes() As Object attributes = myModule.GetCustomAttributes(True) Dim o As [Object] For Each o In attributes Console.WriteLine("Found this attribute on myModule: {0}", o.ToString()) Next o End Sub 'Main End Class 'MyMainClass 'A very simple custom attribute. <AttributeUsage(AttributeTargets.Class Or AttributeTargets.Module)> _ Public Class MySimpleAttribute Inherits Attribute Private name As String Public Sub New(ByVal newName As String) name = newName End Sub 'New End Class 'MySimpleAttribute End Namespace 'ReflectionModule_Examples
using System; using System.Reflection; //Define a module-level attribute. [module: ReflectionModule_Examples.MySimpleAttribute("module-level")] namespace ReflectionModule_Examples { class MyMainClass { static void Main() { Module[] moduleArray; moduleArray = Assembly.GetExecutingAssembly().GetModules(false); // In a simple project with only one module, the module at index // 0 will be the module containing these classes. Module myModule = moduleArray[0]; object[] attributes; attributes = myModule.GetCustomAttributes(true); foreach(Object o in attributes) { Console.WriteLine("Found this attribute on myModule: {0}.", o.ToString()); } } } //A very simple custom attribute. [AttributeUsage(AttributeTargets.Class | AttributeTargets.Module)] public class MySimpleAttribute : Attribute { private string name; public MySimpleAttribute(string newName) { name = newName; } } }
using namespace System; using namespace System::Reflection; using namespace System::Collections; namespace ReflectionModule_Examples { //Define a module-level attribute. //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; } }; [module:MySimpleAttribute("module-level")]; ref class MyMainClass{}; } int main() { array<System::Reflection::Module^>^moduleArray; moduleArray = Assembly::GetExecutingAssembly()->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; attributes = myModule->GetCustomAttributes( true ); IEnumerator^ myEnum = attributes->GetEnumerator(); while ( myEnum->MoveNext() ) { Object^ o = safe_cast<Object^>(myEnum->Current); Console::WriteLine( "Found this attribute on myModule: {0}.", o ); } }
package ReflectionModule_Examples; import System.*; import System.Reflection.*; //Define a module-level attribute. /** @module ReflectionModule_Examples.MySimpleAttribute("module-level") */ class MyMainClass { public static void main(String[] args) { Module moduleArray[]; moduleArray = Assembly.GetExecutingAssembly().GetModules(false); // In a simple project with only one module, the module at index // 0 will be the module containing these classes. Module myModule = (Module)moduleArray.get_Item(0); Object attributes[]; attributes = myModule.GetCustomAttributes(true); for (int iCtr = 0; iCtr < attributes.length; iCtr++) { Object o = ( Object)attributes[iCtr]; Console.WriteLine("Found this attribute on myModule: {0}.", o.ToString()); } } //main } //MyMainClass //A very simple custom attribute. /** @attribute AttributeUsage(AttributeTargets.Class | AttributeTargets.Module) */ public class MySimpleAttribute extends Attribute { private String name; public MySimpleAttribute(String newName) { name = newName; } //MySimpleAttribute } //MySimpleAttribute

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- Module.GetCustomAttributes メソッドのページへのリンク