MemberInfo.DeclaringType MemberInfo.DeclaringType MemberInfo.DeclaringType MemberInfo.DeclaringType Property

Definition

이 멤버를 선언하는 클래스를 가져옵니다. Gets the class that declares this member.

public:
 abstract property Type ^ DeclaringType { Type ^ get(); };
public abstract Type DeclaringType { get; }
member this.DeclaringType : Type
Public MustOverride ReadOnly Property DeclaringType As Type

Property Value

이 멤버를 선언하는 클래스에 대한 Type 개체입니다. The Type object for the class that declares this member.

Implements

Examples

다음 예제에서는 인터페이스를 정의 IValue에 단일 멤버를 사용 하 여 GetValue합니다.The following example defines an interface, IValue, with a single member, GetValue. 네 가지 클래스도 정의: A를 구현 하는 기본 클래스는 IValue ; 인터페이스 B에서 상속한 A 고의 구현을 숨기는 GetValue 기본 클래스 구현을;에서 C를 단순히에서 상속 하는 A; 및 D에서 상속 하는 A 재정의 및 해당 GetValue 메서드.It also defines four classes: A, a base class that implements the IValue interface; B, which inherits from A and hides its implementation of GetValue from the base class implementation; C, which simply inherits from A; and D, which inherits from A and overrides its GetValue method. 그런 다음 검색을 MemberInfo 형식의 각 멤버에 대 한 개체 (에서 상속 된 멤버를 포함 Object)의 값을 표시 하 고 해당 DeclaringType 속성입니다.The example then retrieves a MemberInfo object for each member of the type (including members inherited from Object) and displays the value of its DeclaringType property.

using System;
using System.Reflection;

interface IValue 
{
   int GetValue() ;
};
 
class A : IValue 
{
   public virtual int GetValue() 
   { 
      return 0; 
   }
};
 
class B : A 
{
   public new int GetValue() 
   { 
      return 0; 
   }
};
 
class C : A 
{ };

class D : A
{
   public override int GetValue()
   {
      return 0;
   }
}

public class Example
{
   public static void Main()
   {
      // Get members of IValue interface.
      ShowMembersAndDeclaringTypes(typeof(IValue));
      Console.WriteLine();
      ShowMembersAndDeclaringTypes(typeof(A));
      Console.WriteLine();
      ShowMembersAndDeclaringTypes(typeof(B));
      Console.WriteLine();
      ShowMembersAndDeclaringTypes(typeof(C));
      Console.WriteLine();
      ShowMembersAndDeclaringTypes(typeof(D));
      Console.WriteLine();
   }

   private static void ShowMembersAndDeclaringTypes(Type t)
   {
      MemberInfo[] members = t.GetMembers();
      Console.WriteLine("{0} Members: ", t.Name);
      foreach (var member in members)
         Console.WriteLine("   {0}, Declaring type: {1}", 
                           member.Name, member.DeclaringType.Name); 
   }
}
// The example displays the following output:
//       IValue Members:
//          GetValue, Declaring type: IValue
//       
//       A Members:
//          GetValue, Declaring type: A
//          ToString, Declaring type: Object
//          Equals, Declaring type: Object
//          GetHashCode, Declaring type: Object
//          GetType, Declaring type: Object
//          .ctor, Declaring type: A
//       
//       B Members:
//          GetValue, Declaring type: B
//          GetValue, Declaring type: A
//          ToString, Declaring type: Object
//          Equals, Declaring type: Object
//          GetHashCode, Declaring type: Object
//          GetType, Declaring type: Object
//          .ctor, Declaring type: B
//       
//       C Members:
//          GetValue, Declaring type: A
//          ToString, Declaring type: Object
//          Equals, Declaring type: Object
//          GetHashCode, Declaring type: Object
//          GetType, Declaring type: Object
//          .ctor, Declaring type: C
//       
//       D Members:
//          GetValue, Declaring type: D
//          ToString, Declaring type: Object
//          Equals, Declaring type: Object
//          GetHashCode, Declaring type: Object
//          GetType, Declaring type: Object
//          .ctor, Declaring type: D
Imports System.Reflection

Interface IValue 
   Function GetValue() As Integer 
End Interface
 
Class A : Implements IValue 
   Public Overridable Function GetValue() As Integer _
                               Implements IValue.GetValue 
      Return 0 
   End Function
End Class
 
Class B : Inherits A 
   Public Shadows Function GetValue() As Integer 
      Return 0 
   End Function
End Class
 
Class C : Inherits A 
End Class

Class D : Inherits A
   Public Overrides Function GetValue() As Integer
      Return 0
   End Function
End Class

Public Module Example
   Public Sub Main()
      ' Get members of IValue interface.
      ShowMembersAndDeclaringTypes(GetType(IValue))
      Console.WriteLine()
      ShowMembersAndDeclaringTypes(GetType(A))
      Console.WriteLine()
      ShowMembersAndDeclaringTypes(GetType(B))
      Console.WriteLine()
      ShowMembersAndDeclaringTypes(GetType(C))
      Console.WriteLine()
      ShowMembersAndDeclaringTypes(GetType(D))
      Console.WriteLine()
   End Sub

   Private Sub ShowMembersAndDeclaringTypes(t As Type)
      Dim members() As MemberInfo = t.GetMembers()
      Console.WriteLine("{0} Members: ", t.Name)
      For Each member In members
         Console.WriteLine("   {0}, Declaring type: {1}", 
                           member.Name, member.DeclaringType.Name)
      Next                      
   End Sub
End Module
' The example displays the following output:
'       IValue Members:
'          GetValue, Declaring type: IValue
'       
'       A Members:
'          GetValue, Declaring type: A
'          ToString, Declaring type: Object
'          Equals, Declaring type: Object
'          GetHashCode, Declaring type: Object
'          GetType, Declaring type: Object
'          .ctor, Declaring type: A
'       
'       B Members:
'          GetValue, Declaring type: B
'          GetValue, Declaring type: A
'          ToString, Declaring type: Object
'          Equals, Declaring type: Object
'          GetHashCode, Declaring type: Object
'          GetType, Declaring type: Object
'          .ctor, Declaring type: B
'       
'       C Members:
'          GetValue, Declaring type: A
'          ToString, Declaring type: Object
'          Equals, Declaring type: Object
'          GetHashCode, Declaring type: Object
'          GetType, Declaring type: Object
'          .ctor, Declaring type: C
'       
'       D Members:
'          GetValue, Declaring type: D
'          ToString, Declaring type: Object
'          Equals, Declaring type: Object
'          GetHashCode, Declaring type: Object
'          GetType, Declaring type: Object
'          .ctor, Declaring type: D

형식의 선언에 A.GetValueAB 두 포함 GetValue 메서드를 선언 하 여 A 여 개와 B의 형식 선언 하 고 D.GetValueD.Note that the declaring type of A.GetValue is A, that B includes two GetValue methods, one declared by A and one by B, and that the declaring type of D.GetValue is D.

참고

DeclaringType 멤버 이름과 해당 선언 형식 이름을 반환합니다.DeclaringType returns only the member names and the names of their declaring types. 반환할 멤버는 프로토타입 이름의 호출 MemberInfo.ToString합니다.To return the member names with their prototypes, call MemberInfo.ToString.

Remarks

합니다 DeclaringType 속성에 대 한 참조를 검색 합니다 Type 이 멤버를 선언 하는 형식의 개체입니다.The DeclaringType property retrieves a reference to the Type object for the type that declares this member. 형식의 멤버 형식에 의해 선언 되거나 기본 형식에서 상속 하므로 Type 에서 반환 된 개체를 DeclaringType 속성 아닐 동일를 Type 현재를 가져오는 데 사용 되는 개체 MemberInfo 개체입니다.A member of a type is either declared by the type or inherited from a base type, so the Type object returned by the DeclaringType property might not be the same as the Type object used to obtain the current MemberInfo object.

  • 경우는 Type 이 개체 MemberInfo 개체를 얻어이 멤버를 선언 하지 않았습니다.는 DeclaringType 속성은 해당 기본 형식 중 하나를 나타냅니다.If the Type object from which this MemberInfo object was obtained did not declare this member, the DeclaringType property will represent one of its base types.

  • 경우는 MemberInfo 개체가 멤버인 전역 (에서 가져온 경우에, 합니다 Module.GetMethods 모듈에서 전역 메서드를 반환 하는 메서드), 반환 된 DeclaringType 됩니다 null합니다.If the MemberInfo object is a global member (that is, if it was obtained from the Module.GetMethods method, which returns global methods on a module), the returned DeclaringType will be null.

Applies to