이 문서는 기계로 번역한 것입니다. 원본 텍스트를 보려면 포인터를 문서의 문장 위로 올리십시오. 추가 정보
번역
원본
이 항목은 아직 평가되지 않았습니다.- 이 항목 평가

MemberInfo.IsDefined 메서드

파생 클래스에서 재정의되는 경우 지정된 형식 또는 파생 형식의 특성이 하나 이상 이 멤버에 적용되는지 여부를 나타냅니다.

네임스페이스:  System.Reflection
어셈블리:  mscorlib(mscorlib.dll)
public abstract bool IsDefined(
	Type attributeType,
	bool inherit
)

매개 변수

attributeType
형식: System.Type
검색할 사용자 지정 특성의 형식입니다. 검색 대상에는 파생 형식이 포함됩니다.
inherit
형식: System.Boolean
특성을 찾기 위해 이 멤버의 상속 체인을 검색하려면 true로 설정하고, 그렇지 않으면 false로 설정합니다. 이 매개 변수는 속성과 이벤트의 경우 무시됩니다. 설명 부분을 참조하십시오.

반환 값

형식: System.Boolean
이 멤버에 attributeType 또는 파생 형식의 인스턴스가 하나 이상 적용되면 true이고, 그렇지 않으면 false입니다.

구현

ICustomAttributeProvider.IsDefined(Type, Boolean)
_MemberInfo.IsDefined(Type, Boolean)

이 메서드는 속성과 이벤트에 대한 inherit 매개 변수를 무시합니다. 속성 및 이벤트에서 특성에 대한 상속 체인을 검색하려면 Attribute.IsDefined 메서드의 적절한 오버로드를 사용합니다.

참고참고

.NET Framework 버전 2.0에서 이 메서드는 형식, 메서드 또는 생성자의 보안 특성이 새 메타데이터 형식으로 저장된 경우 true를 반환합니다. 버전 2.0으로 컴파일된 어셈블리는 이 형식을 사용합니다. 이전 버전의 .NET Framework로 컴파일된 어셈블리 및 동적 어셈블리는 이전 XML 형식을 사용합니다. 자세한 내용은 선언적 보안 특성 내보내기를 참조하십시오.

다음 예제에서는 지정된 특성이 지정된 멤버에 적용되었는지 여부를 확인합니다.



using System;
using System.Reflection;

// Define a custom attribute with one named parameter.
[AttributeUsage(AttributeTargets.All)]
public class MyAttribute : Attribute
{
    private string myName;
    public MyAttribute(string name)
    {
        myName = name;
    }
    public string Name
    {
        get
        {
            return myName;
        }
    }
}

// Define a class that has the custom attribute associated with one of its members.
public class MyClass1
{
    [MyAttribute("This is an example attribute.")]
    public void MyMethod(int i)
    {
        return;
    }
}

public class MemberInfo_GetCustomAttributes_IsDefined
{
    public static void Main()
    {
        try
        {
            // Get the type of MyClass1.
            Type myType = typeof(MyClass1);
            // Get the members associated with MyClass1.
            MemberInfo[] myMembers = myType.GetMembers();

            // Display the attributes for each of the members of MyClass1.
            for(int i = 0; i < myMembers.Length; i++)
            {
                // Display the attribute if it is of type MyAttribute.
                if(myMembers[i].IsDefined(typeof(MyAttribute), false))
                {
                    Object[] myAttributes = myMembers[i].GetCustomAttributes(typeof(MyAttribute), false);
                    Console.WriteLine("\nThe attributes of type MyAttribute for the member {0} are: \n",
                        myMembers[i]);
                    for(int j = 0; j < myAttributes.Length; j++)
                        // Display the value associated with the attribute.
                        Console.WriteLine("The value of the attribute is : \"{0}\"",
                            ((MyAttribute)myAttributes[j]).Name);
                }
            }
        }
        catch(Exception e)
        {
            Console.WriteLine("An exception occurred: {0}", e.Message);
        }
    }
}


.NET Framework

4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0에서 지원

.NET Framework Client Profile

4, 3.5 SP1에서 지원

이식 가능한 클래스 라이브러리

이식 가능한 클래스 라이브러리에서 지원

Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008(서버 코어 역할은 지원되지 않음), Windows Server 2008 R2(서버 코어 역할은 SP1 이상에서 지원, Itanium은 지원되지 않음)

.NET Framework에서 모든 플랫폼의 전체 버전을 지원하지는 않습니다. 지원되는 버전의 목록을 보려면 .NET Framework 시스템 요구 사항을 참조하십시오.
이 정보가 도움이 되었습니까?
(1500자 남음)

커뮤니티 추가 항목

추가
© 2013 Microsoft. All rights reserved.