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

MemberInfo.GetCustomAttributes 메서드 (Boolean)

파생 클래스에서 재정의되는 경우 이 멤버에 적용된 모든 사용자 지정 특성의 배열을 반환합니다.

네임스페이스:  System.Reflection
어셈블리:  mscorlib(mscorlib.dll)
public abstract Object[] GetCustomAttributes(
	bool inherit
)

매개 변수

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

반환 값

형식: System.Object[]
이 멤버에 적용된 모든 사용자 지정 특성을 포함하는 배열이며, 정의된 특성이 없는 경우 요소가 없는 배열입니다.

구현

ICustomAttributeProvider.GetCustomAttributes(Boolean)
예외상황
TypeLoadException

사용자 지정 특성 형식을 로드할 수 없는 경우

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

플랫폼 참고 사항

Windows Phone용 Silverlight Windows Phone용 Silverlight
 일부 특성 생성자 인수 및 속성 값은 MemberInfo.GetCustomAttributes 오류를 일으킬 수 있습니다.

다음 예제에서는 사용자 지정 특성을 정의하고 특성을 MyClass.MyMethod에 연결한 다음 런타임에 특성을 검색하여 결과를 표시합니다.

참고참고:

이 예제를 실행하려면 Demo 메서드 및 TextBlock 컨트롤을 사용하는 예제 빌드를 참조하십시오.


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 Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      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++)
         {
            Object[] myAttributes = myMembers[i].GetCustomAttributes(true);
            if (myAttributes.Length > 0)
            {
               outputBlock.Text += String.Format("\nThe attributes for the member {0} are: \n", myMembers[i]) + "\n";
               for (int j = 0; j < myAttributes.Length; j++)
                  outputBlock.Text += String.Format("The type of the attribute is {0}.", myAttributes[j]) + "\n";
            }
         }
      }
      catch (Exception e)
      {
         outputBlock.Text += String.Format("An exception occurred: {0}", e.Message) + "\n";
      }
   }
}


Silverlight

5, 4, 3에서 지원

Windows Phone용 Silverlight

Windows Phone OS 7.1, Windows Phone OS 7.0에서 지원

XNA Framework

Xbox 360, Windows Phone OS 7.0에서 지원

Silverlight에서 지원되는 운영 체제 및 브라우저에 대한 자세한 내용은 지원되는 운영 체제 및 브라우저을 참조하십시오.

이 정보가 도움이 되었습니까?
(1500자 남음)

커뮤니티 추가 항목

추가
Microsoft는 MSDN 웹 사이트에 대한 귀하의 의견을 이해하기 위해 온라인 설문 조사를 진행하고 있습니다. 참여하도록 선택하시면 MSDN 웹 사이트에서 나가실 때 온라인 설문 조사가 표시됩니다.

참여하시겠습니까?
© 2013 Microsoft. All rights reserved.