MemberInfo.DeclaringType プロパティ
アセンブリ: mscorlib (mscorlib.dll 内)

public abstract Type DeclaringType { get; }
/** @property */ public abstract Type get_DeclaringType ()
このメンバを宣言するクラスの Type オブジェクト。

DeclaringType プロパティは、このメンバを宣言する型を表す Type オブジェクトへの参照を取得します。ある型のメンバは、その型によって宣言されるか、基本型から継承されるため、DeclaringType プロパティから返される Type オブジェクトは、現在の MemberInfo オブジェクトを取得するために使用する Type オブジェクトとは、異なる場合があります。

DeclaringType がクラスとインターフェイスに対してどのように機能し、System.IO.BufferedStream クラスのメンバ名と一緒に、これらのメンバを宣言しているクラスを取得する例を次に示します。また、B が仮想メソッド M を A からオーバーライドする場合、実質的に B がこのメソッドを再定義 (再宣言) しています。そのため、このメソッドを最初に宣言したのは A ですが、B.M の MethodInfo は、メソッドの宣言型が A ではなく B であると報告します。
Imports System Imports System.IO Imports System.Reflection Imports Microsoft.VisualBasic Namespace MyNamespace1 Interface i Function MyVar() As Integer End Interface ' DeclaringType for MyVar is i. Class A Implements i Function MyVar() As Integer Implements i.MyVar Return 0 End Function End Class ' DeclaringType for MyVar is A. Class B Inherits A Function MyVars() As Integer Return 0 End Function End Class ' DeclaringType for MyVar is B. Class C Inherits A End Class ' DeclaringType for MyVar is A. End Namespace Namespace MyNamespace2 Class A Public Overridable Sub M() End Sub End Class Class B Inherits A Public Overrides Sub M() End Sub End Class End Namespace Class Mymemberinfo Public Shared Sub Main() Console.WriteLine(ControlChars.Cr & "Reflection.MemberInfo") 'Get the Type and MemberInfo. Dim MyType As Type = Type.GetType("System.IO.BufferedStream") Dim Mymemberinfoarray As MemberInfo() = MyType.GetMembers() 'Get and display the DeclaringType method. Console.WriteLine(ControlChars.Cr & "There are {0} members in {1}.", Mymemberinfoarray.Length, MyType.FullName) Dim Mymemberinfo As MemberInfo For Each Mymemberinfo In Mymemberinfoarray Console.WriteLine("The declaring type of {0} is {1}.", Mymemberinfo.Name, Mymemberinfo.DeclaringType.ToString()) Next Mymemberinfo End Sub End Class
using System; using System.IO; using System.Reflection; namespace MyNamespace1 { interface i { int MyVar() ; }; // DeclaringType for MyVar is i. class A : i { public int MyVar() { return 0; } }; // DeclaringType for MyVar is A. class B : A { new int MyVar() { return 0; } }; // DeclaringType for MyVar is B. class C : A { }; // DeclaringType for MyVar is A. } namespace MyNamespace2 { class Mymemberinfo { public static void Main(string[] args) { Console.WriteLine ("\nReflection.MemberInfo"); //Get the Type and MemberInfo. Type MyType =Type.GetType("System.IO.BufferedStream"); MemberInfo[] Mymemberinfoarray = MyType.GetMembers(); //Get and display the DeclaringType method. Console.WriteLine("\nThere are {0} members in {1}.", Mymemberinfoarray.Length, MyType.FullName); foreach (MemberInfo Mymemberinfo in Mymemberinfoarray) { Console.WriteLine("Declaring type of {0} is {1}.", Mymemberinfo.Name, Mymemberinfo.DeclaringType); } } } } namespace MyNamespace3 { class A { virtual public void M () {} } class B: A { override public void M () {} } }
using namespace System; using namespace System::IO; using namespace System::Reflection; namespace MyNamespace1 { interface class i { int MyVar(); }; // DeclaringType for MyVar is i. ref class A: public i { public: virtual int MyVar() { return 0; } }; // DeclaringType for MyVar is A. ref class B: public A { private: int MyVar() new { return 0; } }; // DeclaringType for MyVar is B. ref class C: public A{}; } // DeclaringType for MyVar is A. int main() { Console::WriteLine( "\nReflection.MemberInfo" ); //Get the Type and MemberInfo. Type^ MyType = Type::GetType( "System.IO.BufferedStream" ); array<MemberInfo^>^Mymemberinfoarray = MyType->GetMembers(); //Get and display the DeclaringType method. Console::WriteLine( "\nThere are {0} members in {1}.", Mymemberinfoarray->Length, MyType->FullName ); System::Collections::IEnumerator^ enum0 = Mymemberinfoarray->GetEnumerator(); while ( enum0->MoveNext() ) { MemberInfo^ Mymemberinfo = safe_cast<MemberInfo^>(enum0->Current); Console::WriteLine( "Declaring type of {0} is {1}.", Mymemberinfo->Name, Mymemberinfo->DeclaringType ); } } namespace MyNamespace3 { ref class A { public: virtual void M(){} }; ref class B: public A { public: virtual void M() override {} }; }
package MyNamespace2; import System.*; import System.IO.*; import System.Reflection.*; class MyMemberInfo { public static void main(String[] args) { Console.WriteLine("\nReflection.MemberInfo"); //Get the Type and MemberInfo. Type myType = Type.GetType("System.IO.BufferedStream"); MemberInfo myMemberInfoArray[] = myType.GetMembers(); //Get and display the DeclaringType method. Console.WriteLine("\nThere are {0} members in {1}.", String.valueOf(myMemberInfoArray.length),myType.get_FullName()); for(int iCtr=0; iCtr < myMemberInfoArray.length; iCtr++) { MemberInfo myMemberInfo = myMemberInfoArray[iCtr]; Console.WriteLine("Declaring type of {0} is {1}.", myMemberInfo.get_Name(),myMemberInfo.get_DeclaringType()); } } //main } //MyMemberInfo
package MyPackage1 { interface i { function MyVar() : int ; }; // DeclaringType for MyVar is i. class A implements i { public function MyVar() : int { return 0; } }; // DeclaringType for MyVar is A. class B extends A { hide function MyVar() : int{ return 0; } }; // DeclaringType for MyVar is B. class C extends A { }; // DeclaringType for MyVar is A. } import System; import System.IO; import System.Reflection; class Mymemberinfo { public static function Main() : void { Console.WriteLine ("\nReflection.MemberInfo"); //Get the Type and MemberInfo. var MyType : Type =Type.GetType("System.IO.BufferedStream"); var Mymemberinfoarray : MemberInfo[] = MyType.GetMembers(); //Get and display the DeclaringType method. Console.Write("\nThere are {0} members in ", Mymemberinfoarray.Length); Console.Write("{0}.", MyType.FullName); for (var i : int in Mymemberinfoarray) { var Mymemberinfo : MemberInfo = Mymemberinfoarray[i]; Console.Write("\n" + Mymemberinfo.Name + " declaring type - " + Mymemberinfo.DeclaringType); } } } Mymemberinfo.Main(); package MyPackage3 { class A { public function M () : void {} } class B extends A { override public function M () : void {} } }
![]() |
---|
DeclaringType は、メンバ名と、そのメンバを宣言しているクラスの型だけを返します。メンバ名と一緒にプロトタイプを返すには、MemberInfo.ToString を呼び出します。 |

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


_MemberInfo.DeclaringType プロパティ
アセンブリ: mscorlib (mscorlib.dll 内)



Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- MemberInfo.DeclaringTypeのページへのリンク