Type.GetProperties メソッド ()
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As Type Dim returnValue As PropertyInfo() returnValue = instance.GetProperties
現在の Type のすべてのパブリック プロパティを表す PropertyInfo オブジェクトの配列。 または 現在の Type にパブリック プロパティが存在しない場合は、PropertyInfo 型の空の配列。

型に対するリフレクション時に Get メソッドによって返される基本クラスのメンバを次の表に示します。
メンバ型 | 非静的 | |
---|---|---|
いいえ | いいえ | |
いいえ | ||
適用なし | 共通型システムの規則では、継承は、プロパティを実装するメソッドの継承と同じになります。リフレクションは、プロパティを名前と署名によって隠ぺいされているとして扱います。下記のメモ 2 を参照してください。 | |
いいえ | はい。メソッド (仮想メソッドと非仮想メソッドの両方) は、名前によって隠蔽することもできますし、名前と署名によって隠蔽することもできます。 | |
いいえ | いいえ | |
適用なし | 共通型システムの規則では、継承は、プロパティを実装するメソッドの継承と同じになります。リフレクションは、プロパティを名前と署名によって隠ぺいされているとして扱います。下記のメモ 2 を参照してください。 |
-
名前と署名による隠ぺいでは、カスタム修飾子、戻り値の型、パラメータの型、sentinel、およびアンマネージ呼び出し規約を含めて、署名のすべての部分が判断の対象となります。これはバイナリ比較です。
-
リフレクションの場合、プロパティおよびイベントは名前と署名によって隠ぺいされています。基本クラスに get アクセサと set アクセサの両方を持つプロパティがあり、派生クラスには get アクセサしかない場合、派生クラスのプロパティにより基本クラスのプロパティが隠ぺいされ、基本クラスの set アクセサにはアクセスできません。
現在の T:System.Type が構築ジェネリック型を表している場合、このメソッドは、型パラメータを適切な型の引数で置き換えて PropertyInfo オブジェクトを返します。
現在の Type がジェネリック型またはジェネリック メソッドの定義の型パラメータを表している場合、このメソッドはクラス制約のプロパティを検索します。

GetProperties メソッドを使用する例を次に示します。
Dim myPropertyInfo() As PropertyInfo ' Get the properties of 'Type' class object. myPropertyInfo = Type.GetType("System.Type").GetProperties() Console.WriteLine("Properties of System.Type are:") Dim i As Integer For i = 0 To myPropertyInfo.Length - 1 Console.WriteLine(myPropertyInfo(i).ToString()) Next i
PropertyInfo[] myPropertyInfo; // Get the properties of 'Type' class object. myPropertyInfo = Type.GetType("System.Type").GetProperties(); Console.WriteLine("Properties of System.Type are:"); for (int i = 0; i < myPropertyInfo.Length; i++) { Console.WriteLine(myPropertyInfo[i].ToString()); }
array<PropertyInfo^>^myPropertyInfo; // Get the properties of 'Type' class object. myPropertyInfo = Type::GetType( "System.Type" )->GetProperties(); Console::WriteLine( "Properties of System.Type are:" ); for ( int i = 0; i < myPropertyInfo->Length; i++ ) { Console::WriteLine( myPropertyInfo[ i ] ); }
PropertyInfo myPropertyInfo[]; // Get the properties of 'Type' class object. myPropertyInfo = Type.GetType("System.Type").GetProperties(); Console.WriteLine("Properties of System.Type are:"); for (int i = 0; i < myPropertyInfo.get_Length(); i++) { Console.WriteLine(myPropertyInfo.get_Item(i).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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Type.GetProperties メソッド (BindingFlags)
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As Type Dim bindingAttr As BindingFlags Dim returnValue As PropertyInfo() returnValue = instance.GetProperties(bindingAttr)
- bindingAttr
検索の実行方法を指定する 1 つ以上の BindingFlags から成るビット マスク。
または
null 参照 (Visual Basic では Nothing) を返す 0。
現在の Type のプロパティのうち、指定したバインディング制約に一致するすべてのプロパティを表す PropertyInfo オブジェクトの配列。 または 現在の Type にプロパティが設定されていないか、またはプロパティの中でバインディング制約に一致するものが存在しない場合は、PropertyInfo 型の空の配列。

パブリックなアクセサが少なくとも 1 つはあるプロパティは、リフレクションに対してパブリックであると見なされます。つまり、type.GetProperty("propertyname", BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static) を呼び出し、そのプロパティを取得できます。
それ以外の場合は、プロパティはプライベートであると見なされるため、そのプロパティを取得するには type.GetProperty("propertyname", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static) を使用する必要があります。
次の BindingFlags フィルタ フラグは、入れ子にされた型で、検索対象に含める型を定義するために使用できます。
-
戻り値を取得するには、BindingFlags.Instance または BindingFlags.Static のいずれかを指定する必要があります。
-
検索対象にパブリックではないプロパティ (つまり、プライベート メンバやプロテクト メンバ) を含めるための BindingFlags.NonPublic を指定します。
-
階層構造の上位にある public 静的メンバおよび protected 静的メンバを検索対象に含めるには、BindingFlags.FlattenHierarchy を指定します。継承クラスの private 静的メンバは含まれません。
次の BindingFlags 修飾フラグは、検索方法を変更するために使用できます。
詳細については、「System.Reflection.BindingFlags」を参照してください。
要求された型がパブリックではなく、呼び出し元に現在のアセンブリ外の非パブリック オブジェクトをリフレクションするための ReflectionPermission がない場合、このメソッドは null 参照 (Visual Basic では Nothing) を返します。
現在の T:System.Type が構築ジェネリック型を表している場合、このメソッドは、型パラメータを適切な型の引数で置き換えて PropertyInfo オブジェクトを返します。
現在の Type がジェネリック型またはジェネリック メソッドの定義の型パラメータを表している場合、このメソッドはクラス制約のプロパティを検索します。

2 つのパブリック プロパティと 1 つのプロテクト プロパティを作成し、指定したバインディング制約に一致するプロパティの情報を表示する例を次に示します。
Imports System Imports System.Reflection Imports System.Reflection.Emit Imports Microsoft.VisualBasic ' Create a class having three properties. Public Class MyTypeClass Public ReadOnly Property MyProperty1() As [String] Get Return "hello" End Get End Property Public ReadOnly Property MyProperty2() As [String] Get Return "hello" End Get End Property Protected ReadOnly Property MyProperty3() As [String] Get Return "hello" End Get End Property End Class 'MyTypeClass Public Class TypeMain Public Shared Sub Main() Dim myType As Type = GetType(MyTypeClass) ' Get the public properties. Dim myPropertyInfo As PropertyInfo() = myType.GetProperties((BindingFlags.Public Or BindingFlags.Instance)) Console.WriteLine("The number of public properties is {0}.", myPropertyInfo.Length.ToString()) ' Display the public properties. DisplayPropertyInfo(myPropertyInfo) ' Get the nonpublic properties. Dim myPropertyInfo1 As PropertyInfo() = myType.GetProperties((BindingFlags.NonPublic Or BindingFlags.Instance)) Console.WriteLine("The number of protected properties is {0}.", myPropertyInfo1.Length.ToString()) ' Display the nonpublic properties. DisplayPropertyInfo(myPropertyInfo1) End Sub 'Main Public Shared Sub DisplayPropertyInfo(ByVal myPropertyInfo() As PropertyInfo) ' Display the information for all properties. Dim i As Integer For i = 0 To myPropertyInfo.Length - 1 Dim myPropInfo As PropertyInfo = CType(myPropertyInfo(i), PropertyInfo) Console.WriteLine("The property name is {0}.", myPropInfo.Name.ToString()) Console.WriteLine("The property type is {0}.", myPropInfo.PropertyType.ToString()) Next i End Sub 'DisplayPropertyInfo End Class 'TypeMain
using System; using System.Reflection; using System.Reflection.Emit; // Create a class having three properties. public class MyTypeClass { public String MyProperty1 { get { return "hello"; } } public String MyProperty2 { get { return "hello"; } } protected String MyProperty3 { get { return "hello"; } } } public class TypeMain { public static void Main() { Type myType =(typeof(MyTypeClass)); // Get the public properties. PropertyInfo[] myPropertyInfo = myType.GetProperties(BindingFlags.Public|BindingFlags.Instance); Console.WriteLine("The mumber of public properties is {0}.", myPropertyInfo.Length); // Display the public properties. DisplayPropertyInfo(myPropertyInfo); // Get the nonpublic properties. PropertyInfo[] myPropertyInfo1 = myType.GetProperties(BindingFlags.NonPublic|BindingFlags.Instance); Console.WriteLine("The number of protected properties is {0}.", myPropertyInfo1.Length); // Display all the nonpublic properties. DisplayPropertyInfo(myPropertyInfo1); } public static void DisplayPropertyInfo(PropertyInfo[] myPropertyInfo) { // Display information for all properties. for(int i=0;i<myPropertyInfo.Length;i++) { PropertyInfo myPropInfo = (PropertyInfo)myPropertyInfo[i]; Console.WriteLine("The property name is {0}.", myPropInfo.Name); Console.WriteLine("The property type is {0}.", myPropInfo.PropertyType); } } }
using namespace System; using namespace System::Reflection; using namespace System::Reflection::Emit; // Create a class having three properties. public ref class MyTypeClass { public: property String^ MyProperty1 { String^ get() { return "hello"; } } property String^ MyProperty2 { String^ get() { return "hello"; } } protected: property String^ MyProperty3 { String^ get() { return "hello"; } } }; void DisplayPropertyInfo( array<PropertyInfo^>^myPropertyInfo ) { // Display information for all properties. for ( int i = 0; i < myPropertyInfo->Length; i++ ) { PropertyInfo^ myPropInfo = myPropertyInfo[ i ]; Console::WriteLine( "The property name is {0}.", myPropInfo->Name ); Console::WriteLine( "The property type is {0}.", myPropInfo->PropertyType ); } } int main() { Type^ myType = MyTypeClass::typeid; // Get the public properties. array<PropertyInfo^>^myPropertyInfo = myType->GetProperties( static_cast<BindingFlags>(BindingFlags::Public | BindingFlags::Instance) ); Console::WriteLine( "The mumber of public properties is {0}.", myPropertyInfo->Length ); // Display the public properties. DisplayPropertyInfo( myPropertyInfo ); // Get the nonpublic properties. array<PropertyInfo^>^myPropertyInfo1 = myType->GetProperties( static_cast<BindingFlags>(BindingFlags::NonPublic | BindingFlags::Instance) ); Console::WriteLine( "The number of protected properties is {0}.", myPropertyInfo1->Length ); // Display all the nonpublic properties. DisplayPropertyInfo( myPropertyInfo1 ); }
import System.*; import System.Reflection.*; import System.Reflection.Emit.*; // Create a class having three properties. public class MyTypeClass { /** @property */ public String get_MyProperty1() { return "hello"; }//MyProperty1 /** @property */ public String get_MyProperty2() { return "hello"; }//MyProperty2 /** @property */ protected String get_MyProperty3() { return "hello"; }//Myproperty3 } //MyTypeClass public class TypeMain { public static void main(String[] args) { Type myType = MyTypeClass.class.ToType(); // Get the public properties. PropertyInfo myPropertyInfo[] = myType.GetProperties(BindingFlags. Public | BindingFlags.Instance); Console.WriteLine("The mumber of public properties is {0}.", System.Convert.ToString(myPropertyInfo.get_Length())); // Display the public properties. DisplayPropertyInfo(myPropertyInfo); // Get the nonpublic properties. PropertyInfo myPropertyInfo1[] = myType.GetProperties(BindingFlags. NonPublic | BindingFlags.Instance); Console.WriteLine("The number of protected properties is {0}.", System.Convert.ToString(myPropertyInfo1.get_Length())); // Display all the nonpublic properties. DisplayPropertyInfo(myPropertyInfo1); } //main public static void DisplayPropertyInfo(PropertyInfo myPropertyInfo[]) { // Display information for all properties. for (int i = 0; i < myPropertyInfo.get_Length(); i++) { PropertyInfo myPropInfo = (PropertyInfo)myPropertyInfo.get_Item(i); Console.WriteLine("The property name is {0}.", myPropInfo.get_Name()); Console.WriteLine("The property type is {0}.", myPropInfo.GetType()); } } //DisplayPropertyInfo } //TypeMain

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Type.GetProperties メソッド

名前 | 説明 |
---|---|
Type.GetProperties () | 現在の Type のすべてのパブリック プロパティを返します。 .NET Compact Framework によってサポートされています。 |
Type.GetProperties (BindingFlags) | 派生クラスによってオーバーライドされた場合、指定したバインディング制約を使用して、現在の Type のプロパティを検索します。 .NET Compact Framework によってサポートされています。 |

_Type.GetProperties メソッド
- Type.GetPropertiesのページへのリンク