Module.IsDefined(Type, Boolean) 메서드

정의

이 모듈에 지정된 특성 형식이 적용되었는지 여부를 나타내는 값을 반환합니다.

public:
 virtual bool IsDefined(Type ^ attributeType, bool inherit);
public virtual bool IsDefined (Type attributeType, bool inherit);
abstract member IsDefined : Type * bool -> bool
override this.IsDefined : Type * bool -> bool
Public Overridable Function IsDefined (attributeType As Type, inherit As Boolean) As Boolean

매개 변수

attributeType
Type

테스트할 사용자 지정 특성의 형식입니다.

inherit
Boolean

이 인수는 이 형식의 개체에 대해 무시됩니다.

반환

Boolean

하나 이상의 attributeType 인스턴스가 이 모듈에 적용되었으면 true이고, 그렇지 않으면 false입니다.

구현

예외

attributeType이(가) null인 경우

attributeType이 런타임에 제공되는 Type 개체가 아닌 경우. 예를 들어 attributeTypeTypeBuilder 개체인 경우입니다.

예제

다음 예제를 사용 하는 방법을 보여 줍니다는 IsDefined 메서드.

using namespace System;
using namespace System::Reflection;

namespace ReflectionModule_Examples
{

   //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 ];
   Type^ myType;
   myType = myModule->GetType( "ReflectionModule_Examples.MySimpleAttribute" );
   Console::WriteLine( "IsDefined(MySimpleAttribute) = {0}", myModule->IsDefined( myType, false ) );
}
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 = typeof(MyMainClass).Assembly.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];

            Type myType;
            myType = myModule.GetType("ReflectionModule_Examples.MySimpleAttribute");
            Console.WriteLine("IsDefined(MySimpleAttribute) = {0}", myModule.IsDefined(myType, false));
        }
    }

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

        public MySimpleAttribute(string newName)
        {
            name = newName;
        }
    }
}
Imports System.Reflection

'Define a module-level attribute.
<Module: ReflectionModule_Examples.MySimpleAttribute("module-level")> 

'Define a module-level attribute.
Namespace ReflectionModule_Examples
    Class MyMainClass
        Shared Sub Main()
            Dim moduleArray() As [Module]

            moduleArray = GetType(MyMainClass).Assembly.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 myType As Type
            myType = myModule.GetType("ReflectionModule_Examples.MySimpleAttribute")
            Console.WriteLine("IsDefined(MySimpleAttribute) = {0}", myModule.IsDefined(myType, False))
        End Sub
    End Class

    '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
    End Class
End Namespace 'ReflectionModule_Examples

적용 대상