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

定義

このメンバーを宣言するクラスを取得します。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

プロパティ値

このメンバーを宣言するクラスの Type オブジェクト。The Type object for the class that declares this member.

実装

次の例では、インターフェイス、 IValue、1 つのメンバーでGetValueします。The following example defines an interface, IValue, with a single member, GetValue. 4 つのクラスも定義されています: 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.GetValueA、そのB2 つGetValueメソッド、1 つで宣言されているAによって 1 つB、ことは、宣言の型とD.GetValueDNote 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.

注釈

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なりますnullIf 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.

適用対象