Type.GetProperty メソッド (String, Type, Type[], ParameterModifier[])
アセンブリ: mscorlib (mscorlib.dll 内)

Public Function GetProperty ( _ name As String, _ returnType As Type, _ types As Type(), _ modifiers As ParameterModifier() _ ) As PropertyInfo
Dim instance As Type Dim name As String Dim returnType As Type Dim types As Type() Dim modifiers As ParameterModifier() Dim returnValue As PropertyInfo returnValue = instance.GetProperty(name, returnType, types, modifiers)
public PropertyInfo GetProperty ( string name, Type returnType, Type[] types, ParameterModifier[] modifiers )
public: virtual PropertyInfo^ GetProperty ( String^ name, Type^ returnType, array<Type^>^ types, array<ParameterModifier>^ modifiers ) sealed
public final PropertyInfo GetProperty ( String name, Type returnType, Type[] types, ParameterModifier[] modifiers )
public final function GetProperty ( name : String, returnType : Type, types : Type[], modifiers : ParameterModifier[] ) : PropertyInfo
- types
取得するインデックス付きプロパティに対するパラメータの数値、順序、および型を表す Type オブジェクトの配列。
または
インデックス付けされていないプロパティを取得するための、Type 型の空の配列 (Type[] types = new Type[0])。
指定した要件と一致するパブリック プロパティが存在する場合は、そのパブリック プロパティを表す PropertyInfo オブジェクト。それ以外の場合は null 参照 (Visual Basic では Nothing)。


既定のバインダは ParameterModifier (modifiers パラメータ) を処理しませんが、System.Reflection.Binder 抽象クラスを使用してmodifiers を処理するカスタム バインダを記述できます。ParameterModifier は、COM 相互運用機能によって呼び出すときだけに使用され、参照渡しされるパラメータだけが処理されます。
types 配列と modifiers 配列の長さが同じです。types 配列で指定するパラメータには、modifiers 配列で指定されている pdIn、pdOut、pdLcid、pdRetval、pdOptional、pdHasDefault の各属性を設定できます。これらの属性は、それぞれ [In]、[Out]、[lcid]、[retval]、[optional]、およびパラメータが既定値を持つかどうかを指定する値を表します。パラメータに関連付けられた属性はメタデータに格納され、相互運用性を拡張します。
name の検索では大文字と小文字が区別されます。検索には、public static および public のインスタンス プロパティが含まれます。
要求された型がパブリックではなく、呼び出し元に現在のアセンブリ外の非パブリック オブジェクトをリフレクションするための ReflectionPermission がない場合、このメソッドは null 参照 (Visual Basic では Nothing) を返します。
現在の T:System.Type が構築ジェネリック型を表している場合、このメソッドは、型パラメータを適切な型の引数で置き換えて PropertyInfo を返します。
現在の Type がジェネリック型またはジェネリック メソッドの定義の型パラメータを表している場合、このメソッドはクラス制約のプロパティを検索します。

MyPropertyClass に対応する Type オブジェクトを取得し、GetProperty メソッドに渡される引数を使用して、このクラスのインデックス付きプロパティを取得する例を次に示します。
Imports System Imports System.Reflection Public Class MyPropertyClass Private myPropertyArray(9, 9) As Integer ' Declare an indexer. Default Public Property Item(ByVal i As Integer, ByVal j As Integer) As Integer Get Return myPropertyArray(i, j) End Get Set(ByVal Value As Integer) myPropertyArray(i, j) = Value End Set End Property End Class 'MyPropertyClass Public Class MyTypeClass Public Shared Sub Main() Try Dim myType As Type = GetType(MyPropertyClass) Dim myTypeArray(1) As Type ' Create an instance of a Type array representing the number, order ' and type of the parameters for the property. myTypeArray.SetValue(GetType(Integer), 0) myTypeArray.SetValue(GetType(Integer), 1) ' Search for the indexed property whose parameters match the ' specified argument types and modifiers. Dim myPropertyInfo As PropertyInfo = myType.GetProperty("Item", _ GetType(Integer), myTypeArray, Nothing) Console.WriteLine(myType.FullName + "." + myPropertyInfo.Name + _ " has a property type of " + myPropertyInfo.PropertyType.ToString()) Catch ex As Exception Console.WriteLine("An exception occurred " + ex.Message.ToString()) End Try End Sub 'Main End Class 'MyTypeClass
using System; using System.Reflection; public class MyPropertyClass { private int [,] myPropertyArray = new int[10,10]; // Declare an indexer. public int this [int i,int j] { get { return myPropertyArray[i,j]; } set { myPropertyArray[i,j] = value; } } } public class MyTypeClass { public static void Main() { try { Type myType=typeof(MyPropertyClass); Type[] myTypeArray = new Type[2]; // Create an instance of the Type array representing the number, order // and type of the parameters for the property. myTypeArray.SetValue(typeof(int),0); myTypeArray.SetValue(typeof(int),1); // Search for the indexed property whose parameters match the // specified argument types and modifiers. PropertyInfo myPropertyInfo = myType.GetProperty("Item", typeof(int),myTypeArray,null); Console.WriteLine(myType.FullName + "." + myPropertyInfo.Name + " has a property type of " + myPropertyInfo.PropertyType); } catch(Exception ex) { Console.WriteLine("An exception occurred " + ex.Message); } } }
using namespace System; using namespace System::Reflection; public ref class MyPropertyClass { private: array<int, 2>^ myPropertyArray; public: property int Item [int, int] { // Declare an indexer. int get( int i, int j ) { return myPropertyArray[ i,j ]; } void set( int i, int j, int value ) { myPropertyArray[ i,j ] = value; } } }; int main() { try { Type^ myType = MyPropertyClass::typeid; array<Type^>^myTypeArray = gcnew array<Type^>(2); // Create an instance of the Type array representing the number, order // and type of the parameters for the property. myTypeArray->SetValue( int::typeid, 0 ); myTypeArray->SetValue( int::typeid, 1 ); // Search for the indexed property whose parameters match the // specified argument types and modifiers. PropertyInfo^ myPropertyInfo = myType->GetProperty( "Item", int::typeid, myTypeArray, nullptr ); Console::WriteLine( "{0}.{1} has a property type of {2}", myType->FullName, myPropertyInfo->Name, myPropertyInfo->PropertyType ); } catch ( Exception^ ex ) { Console::WriteLine( "An exception occurred {0}", ex->Message ); } }
import System.*; import System.Reflection.*; public class MyPropertyClass { private int myPropertyArray[,] = new int[10, 10]; // Declare an indexer. /** @property */ public int get_Item(int i, int j) { return myPropertyArray[i, j]; } //Item /** @property */ public void set_Item(int i, int j, int value) { myPropertyArray[i, j] = value; } //Item } //MyPropertyClass public class MyTypeClass { public static void main(String[] args) { try { Type myType = MyPropertyClass.class.ToType(); Type myTypeArray[] = new Type[2]; // Create an instance of the Type array representing the number, // order and type of the parameters for the property. myTypeArray.SetValue(int.class.ToType(), 0); myTypeArray.SetValue(int.class.ToType(), 1); // Search for the indexed property whose parameters match the // specified argument types and modifiers. PropertyInfo myPropertyInfo = myType.GetProperty("Item", int.class.ToType(), myTypeArray, null); Console.WriteLine(myType.get_FullName() + "." + myPropertyInfo. get_Name() + " has a property type of " + myPropertyInfo. GetType()); } catch (System.Exception ex) { Console.WriteLine("An exception occurred " + ex.get_Message()); } } //main } //MyTypeClass

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


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

Dim instance As Type Dim name As String Dim returnType As Type Dim returnValue As PropertyInfo returnValue = instance.GetProperty(name, returnType)
戻り値
指定した名前のパブリック プロパティが存在する場合は、そのパブリック プロパティを表す PropertyInfo オブジェクト。それ以外の場合は null 参照 (Visual Basic では Nothing)。


name の検索では大文字と小文字が区別されます。検索には、public static および public のインスタンス プロパティが含まれます。
要求された型がパブリックではなく、呼び出し元に現在のアセンブリ外の非パブリック オブジェクトをリフレクションするための ReflectionPermission がない場合、このメソッドは null 参照 (Visual Basic では Nothing) を返します。
現在の T:System.Type が構築ジェネリック型を表している場合、このメソッドは、型パラメータを適切な型の引数で置き換えて PropertyInfo を返します。
現在の Type がジェネリック型またはジェネリック メソッドの定義の型パラメータを表している場合、このメソッドはクラス制約のプロパティを検索します。

1 つのプロパティを持つクラスを定義し、そのプロパティの名前と型を取得する例を次に示します。
Imports System Imports System.Reflection Class MyClass1 Private myMessage As [String] = "Hello World." Public Property MyProperty1() As String Get Return myMessage End Get Set(ByVal Value As String) myMessage = Value End Set End Property End Class 'MyClass1 Class TestClass Shared Sub Main() Try Dim myType As Type = GetType(MyClass1) ' Get the PropertyInfo object representing MyProperty1. Dim myStringProperties1 As PropertyInfo = myType.GetProperty("MyProperty1", GetType(String)) Console.WriteLine("The name of the first property of MyClass1 is {0}.", myStringProperties1.Name) Console.WriteLine("The type of the first property of MyClass1 is {0}.", myStringProperties1.PropertyType.ToString()) Catch e As ArgumentNullException Console.WriteLine("ArgumentNullException :" + e.Message.ToString()) Catch e As AmbiguousMatchException Console.WriteLine("AmbiguousMatchException :" + e.Message.ToString()) Catch e As NullReferenceException Console.WriteLine("Source : {0}", e.Source.ToString()) Console.WriteLine("Message : {0}", e.Message.ToString()) End Try End Sub 'Main End Class 'TestClass
using System; using System.Reflection; class MyClass1 { String myMessage="Hello World."; public string MyProperty1 { get { return myMessage; } set { myMessage =value; } } } class TestClass { static void Main() { try { Type myType = typeof(MyClass1); // Get the PropertyInfo object representing MyProperty1. PropertyInfo myStringProperties1 = myType.GetProperty("MyProperty1" , typeof(string)); Console.WriteLine("The name of the first property of MyClass1 is {0}.", myStringProperties1.Name); Console.WriteLine("The type of the first property of MyClass1 is {0}.", myStringProperties1.PropertyType); } catch(ArgumentNullException e) { Console.WriteLine("ArgumentNullException :"+e.Message); } catch(AmbiguousMatchException e) { Console.WriteLine("AmbiguousMatchException :"+e.Message); } catch(NullReferenceException e) { Console.WriteLine("Source : {0}" , e.Source); Console.WriteLine("Message : {0}" , e.Message); } } }
using namespace System; using namespace System::Reflection; ref class MyClass1 { private: String^ myMessage; public: property String^ MyProperty1 { String^ get() { return myMessage; } void set( String^ value ) { myMessage = value; } } }; int main() { try { Type^ myType = MyClass1::typeid; // Get the PropertyInfo Object* representing MyProperty1. PropertyInfo^ myStringProperties1 = myType->GetProperty( "MyProperty1", String::typeid ); Console::WriteLine( "The name of the first property of MyClass1 is {0}.", myStringProperties1->Name ); Console::WriteLine( "The type of the first property of MyClass1 is {0}.", myStringProperties1->PropertyType ); } catch ( ArgumentNullException^ e ) { Console::WriteLine( "ArgumentNullException : {0}", e->Message ); } catch ( AmbiguousMatchException^ e ) { Console::WriteLine( "AmbiguousMatchException : {0}", e->Message ); } catch ( NullReferenceException^ e ) { Console::WriteLine( "Source : {0}", e->Source ); Console::WriteLine( "Message : {0}", e->Message ); } }
import System.*; import System.Reflection.*; class MyClass1 { private String myMessage = "Hello World."; /** @property */ public String get_MyProperty1() { return myMessage; } //MyProperty1 /** @property */ public void set_MyProperty1(String value) { myMessage = value; } //MyProperty1 } //MyClass1 class TestClass { public static void main(String[] args) { try { Type myType = MyClass1.class.ToType(); // Get the PropertyInfo object representing MyProperty1. PropertyInfo myStringProperties1 = myType.GetProperty("MyProperty1" , String.class.ToType()); Console.WriteLine("The name of the first property of MyClass1" + " is {0}.", myStringProperties1.get_Name()); Console.WriteLine("The type of the first property of MyClass1" + " is {0}.", myStringProperties1.GetType()); } catch (ArgumentNullException e) { Console.WriteLine("ArgumentNullException :" + e.get_Message()); } catch (AmbiguousMatchException e) { Console.WriteLine("AmbiguousMatchException :" + e.get_Message()); } catch (NullReferenceException e) { Console.WriteLine("Source : {0}", e.get_Source()); Console.WriteLine("Message : {0}", e.get_Message()); } } //main } //TestClass

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.GetProperty メソッド (String, Type[])
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As Type Dim name As String Dim types As Type() Dim returnValue As PropertyInfo returnValue = instance.GetProperty(name, types)
- types
取得するインデックス付きプロパティに対するパラメータの数値、順序、および型を表す Type オブジェクトの配列。
または
インデックス付けされていないプロパティを取得するための、Type 型の空の配列 (Type[] types = new Type[0])。
指定した引数型と一致するパラメータが設定されているパブリック プロパティが存在する場合は、そのパブリック プロパティを表す PropertyInfo オブジェクト。それ以外の場合は null 参照 (Visual Basic では Nothing)。


name の検索では大文字と小文字が区別されます。検索には、public static および public のインスタンス プロパティが含まれます。
要求された型がパブリックではなく、呼び出し元に現在のアセンブリ外の非パブリック オブジェクトをリフレクションするための ReflectionPermission がない場合、このメソッドは null 参照 (Visual Basic では Nothing) を返します。
現在の T:System.Type が構築ジェネリック型を表している場合、このメソッドは、型パラメータを適切な型の引数で置き換えて PropertyInfo を返します。
現在の Type がジェネリック型またはジェネリック メソッドの定義の型パラメータを表している場合、このメソッドはクラス制約のプロパティを検索します。

ユーザー定義クラスの Type オブジェクトと、そのクラスのプロパティを取得して、GetProperty に渡される引数の指定に従ってプロパティ名とプロパティの型を表示する例を次に示します。
Imports System Imports System.Reflection Module Module1 Class MyClass1 Private myArray As Integer(,) = {{1, 2}, {3, 4}} ' Declare an indexer. Default Public Property Item(ByVal i As Integer, ByVal j As Integer) As Integer Get Return myArray(i, j) End Get Set(ByVal Value As Integer) myArray(i, j) = Value End Set End Property End Class 'MyClass1 Public Class MyTypeClass Public Shared Sub Main() Try ' Get the Type Object. Dim myType As Type = GetType(MyClass1) Dim myTypeArr(1) As Type ' Create an instance of a Type array. myTypeArr.SetValue(GetType(Integer), 0) myTypeArr.SetValue(GetType(Integer), 1) ' Get the PropertyInfo object for the indexed property Item, which has two integer parameters. Dim myPropInfo As PropertyInfo = myType.GetProperty("Item", myTypeArr) ' Display the property. Console.WriteLine("The {0} property exists in MyClass1.", myPropInfo.ToString()) Catch e As NullReferenceException Console.WriteLine("An exception occurred.") Console.WriteLine("Source : {0}", e.Source.ToString()) Console.WriteLine("Message : {0}", e.Message.ToString()) End Try End Sub 'Main End Class 'MyTypeClass End Module 'Module1
using System; using System.Reflection; class MyClass1 { private int [,] myArray = {{1,2},{3,4}}; // Declare an indexer. public int this [int i,int j] { get { return myArray[i,j]; } set { myArray[i,j] = value; } } } public class MyTypeClass { public static void Main(string[] args) { try { // Get the Type object. Type myType=typeof(MyClass1); Type[] myTypeArr = new Type[2]; // Create an instance of a Type array. myTypeArr.SetValue(typeof(int),0); myTypeArr.SetValue(typeof(int),1); // Get the PropertyInfo object for the indexed property Item, which has two integer parameters. PropertyInfo myPropInfo = myType.GetProperty("Item", myTypeArr); // Display the property. Console.WriteLine("The {0} property exists in MyClass1.", myPropInfo.ToString()); } catch(NullReferenceException e) { Console.WriteLine("An exception occurred."); Console.WriteLine("Source : {0}" , e.Source); Console.WriteLine("Message : {0}" , e.Message); } } }
using namespace System; using namespace System::Reflection; ref class MyClass1 { private: array<int, 2>^myArray; public: property int Item [int, int] { // Declare an indexer. int get( int i, int j ) { return myArray[ i,j ]; } void set( int i, int j, int value ) { myArray[ i,j ] = value; } } }; int main() { try { // Get the Type object. Type^ myType = MyClass1::typeid; array<Type^>^myTypeArr = gcnew array<Type^>(2); // Create an instance of a Type array. myTypeArr->SetValue( int::typeid, 0 ); myTypeArr->SetValue( int::typeid, 1 ); // Get the PropertyInfo object for the indexed property Item, which has two integer parameters. PropertyInfo^ myPropInfo = myType->GetProperty( "Item", myTypeArr ); // Display the property. Console::WriteLine( "The {0} property exists in MyClass1.", myPropInfo ); } catch ( NullReferenceException^ e ) { Console::WriteLine( "An exception occurred." ); Console::WriteLine( "Source : {0}", e->Source ); Console::WriteLine( "Message : {0}", e->Message ); } }
import System.*; import System.Reflection.*; class MyClass1 { private int myArray[,] = {{1, 2}, {3, 4}}; // Declare an indexer. /** @property */ public int get_Item(int i, int j) { return myArray[i, j]; } //Item /** @property */ public void set_Item(int i, int j, int value) { myArray[i, j] = value; } //Item } //MyClass1 public class MyTypeClass { public static void main(String[] args) { try { // Get the Type object. Type myType = MyClass1.class.ToType(); Type myTypeArr[] = new Type[2]; // Create an instance of a Type array. myTypeArr.SetValue(int.class.ToType(), 0); myTypeArr.SetValue(int.class.ToType(), 1); // Get the PropertyInfo object for the indexed property Item, // which has two integer parameters. PropertyInfo myPropInfo = myType.GetProperty("Item", myTypeArr); // Display the property. Console.WriteLine("The {0} property exists in MyClass1.", myPropInfo.ToString()); } catch (NullReferenceException e) { Console.WriteLine("An exception occurred."); Console.WriteLine("Source : {0}", e.get_Source()); Console.WriteLine("Message : {0}", e.get_Message()); } } //main } //MyTypeClass
内部的には、このプロパティはメタデータで "Item" という名前で参照されます。したがって、リフレクションを使用して PropertyInfo を取得する場合は、正しい PropertyInfo が返されるように、この内部名を指定する必要があります。

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


Type.GetProperty メソッド (String, BindingFlags, Binder, Type, Type[], ParameterModifier[])
アセンブリ: mscorlib (mscorlib.dll 内)

Public Function GetProperty ( _ name As String, _ bindingAttr As BindingFlags, _ binder As Binder, _ returnType As Type, _ types As Type(), _ modifiers As ParameterModifier() _ ) As PropertyInfo
Dim instance As Type Dim name As String Dim bindingAttr As BindingFlags Dim binder As Binder Dim returnType As Type Dim types As Type() Dim modifiers As ParameterModifier() Dim returnValue As PropertyInfo returnValue = instance.GetProperty(name, bindingAttr, binder, returnType, types, modifiers)
public PropertyInfo GetProperty ( string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers )
public: virtual PropertyInfo^ GetProperty ( String^ name, BindingFlags bindingAttr, Binder^ binder, Type^ returnType, array<Type^>^ types, array<ParameterModifier>^ modifiers ) sealed
public final PropertyInfo GetProperty ( String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers )
public final function GetProperty ( name : String, bindingAttr : BindingFlags, binder : Binder, returnType : Type, types : Type[], modifiers : ParameterModifier[] ) : PropertyInfo
- bindingAttr
検索の実行方法を指定する 1 つ以上の BindingFlags から成るビット マスク。
または
null 参照 (Visual Basic では Nothing) を返す 0。
- binder
一連のプロパティを定義し、バインディングを有効にする Binder オブジェクト。バインディングには、オーバーロードされたメソッドの選択、引数の型の強制変換、リフレクションによるメンバの呼び出しなどが含まれます。
または
DefaultBinder を使用する場合は null 参照 (Visual Basic では Nothing)。
- types
取得するインデックス付きプロパティに対するパラメータの数値、順序、および型を表す Type オブジェクトの配列。
または
インデックス付けされていないプロパティを取得するための、Type 型の空の配列 (Type[] types = new Type[0])。
指定した要件と一致するプロパティが存在する場合は、そのプロパティを表す PropertyInfo オブジェクト。それ以外の場合は null 参照 (Visual Basic では Nothing)。


既定のバインダは ParameterModifier (modifiers パラメータ) を処理しませんが、System.Reflection.Binder 抽象クラスを使用してmodifiers を処理するカスタム バインダを記述できます。ParameterModifier は、COM 相互運用機能によって呼び出すときだけに使用され、参照渡しされるパラメータだけが処理されます。
型に対するリフレクション時に Get メソッドによって返される基本クラスのメンバを次の表に示します。
メンバ型 | 非静的 | |
---|---|---|
いいえ | いいえ | |
いいえ | ||
適用なし | 共通型システムの規則では、継承は、プロパティを実装するメソッドの継承と同じになります。リフレクションは、プロパティを名前と署名によって隠ぺいされているとして扱います。下記のメモ 2 を参照してください。 | |
いいえ | はい。メソッド (仮想メソッドと非仮想メソッドの両方) は、名前によって隠蔽することもできますし、名前と署名によって隠蔽することもできます。 | |
いいえ | いいえ | |
適用なし | 共通型システムの規則では、継承は、プロパティを実装するメソッドの継承と同じになります。リフレクションは、プロパティを名前と署名によって隠ぺいされているとして扱います。下記のメモ 2 を参照してください。 |
-
名前と署名による隠ぺいでは、カスタム修飾子、戻り値の型、パラメータの型、sentinel、およびアンマネージ呼び出し規約を含めて、署名のすべての部分が判断の対象となります。これはバイナリ比較です。
-
リフレクションの場合、プロパティおよびイベントは名前と署名によって隠ぺいされています。基本クラスに get アクセサと set アクセサの両方を持つプロパティがあり、派生クラスには get アクセサしかない場合、派生クラスのプロパティにより基本クラスのプロパティが隠ぺいされ、基本クラスの set アクセサにはアクセスできません。
types 配列と modifiers 配列の長さが同じです。types 配列で指定するパラメータには、modifiers 配列で指定されている pdIn、pdOut、pdLcid、pdRetval、pdOptional、pdHasDefault の各属性を設定できます。これらの属性は、それぞれ [In]、[Out]、[lcid]、[retval]、[optional]、およびパラメータが既定値を持つかどうかを指定する値を表します。パラメータに関連付けられた属性はメタデータに格納され、相互運用性を拡張します。
次の 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 がジェネリック型またはジェネリック メソッドの定義の型パラメータを表している場合、このメソッドはクラス制約のプロパティを検索します。

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


Type.GetProperty メソッド (String, Type, Type[])
アセンブリ: mscorlib (mscorlib.dll 内)

Public Function GetProperty ( _ name As String, _ returnType As Type, _ types As Type() _ ) As PropertyInfo
Dim instance As Type Dim name As String Dim returnType As Type Dim types As Type() Dim returnValue As PropertyInfo returnValue = instance.GetProperty(name, returnType, types)
public: virtual PropertyInfo^ GetProperty ( String^ name, Type^ returnType, array<Type^>^ types ) sealed
public final function GetProperty ( name : String, returnType : Type, types : Type[] ) : PropertyInfo
- types
取得するインデックス付きプロパティに対するパラメータの数値、順序、および型を表す Type オブジェクトの配列。
または
インデックス付けされていないプロパティを取得するための、Type 型の空の配列 (Type[] types = new Type[0])。
指定した引数型と一致するパラメータが設定されているパブリック プロパティが存在する場合は、そのパブリック プロパティを表す PropertyInfo オブジェクト。それ以外の場合は null 参照 (Visual Basic では Nothing)。


name の検索では大文字と小文字が区別されます。検索には、public static および public のインスタンス プロパティが含まれます。
要求された型がパブリックではなく、呼び出し元に現在のアセンブリ外の非パブリック オブジェクトをリフレクションするための ReflectionPermission がない場合、このメソッドは null 参照 (Visual Basic では Nothing) を返します。
現在の T:System.Type が構築ジェネリック型を表している場合、このメソッドは、型パラメータを適切な型の引数で置き換えて PropertyInfo を返します。
現在の Type がジェネリック型またはジェネリック メソッドの定義の型パラメータを表している場合、このメソッドはクラス制約のプロパティを検索します。

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


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

Dim instance As Type Dim name As String Dim returnValue As PropertyInfo returnValue = instance.GetProperty(name)
戻り値
指定した名前のパブリック プロパティが存在する場合は、そのパブリック プロパティを表す PropertyInfo オブジェクト。それ以外の場合は null 参照 (Visual Basic では Nothing)。


name の検索では大文字と小文字が区別されます。検索には、public static および public のインスタンス プロパティが含まれます。
要求された型がパブリックではなく、呼び出し元に現在のアセンブリ外の非パブリック オブジェクトをリフレクションするための ReflectionPermission がない場合、このメソッドは null 参照 (Visual Basic では Nothing) を返します。
現在の T:System.Type が構築ジェネリック型を表している場合、このメソッドは、型パラメータを適切な型の引数で置き換えて PropertyInfo を返します。
現在の Type がジェネリック型またはジェネリック メソッドの定義の型パラメータを表している場合、このメソッドはクラス制約のプロパティを検索します。

ユーザー定義クラスの Type オブジェクトと、そのクラスのプロパティを取得して、プロパティ名を表示する例を次に示します。
Imports System Imports System.Reflection Class MyClass1 Private myProperty1 As Integer ' Declare MyProperty. Public Property MyProperty() As Integer Get Return myProperty1 End Get Set(ByVal Value As Integer) myProperty1 = Value End Set End Property End Class 'MyClass1 Public Class MyTypeClass Public Shared Sub Main(ByVal args() As String) Try ' Get Type Object corresponding to MyClass. Dim myType As Type = GetType(MyClass1) ' Get PropertyInfo object by passing property name. Dim myPropInfo As PropertyInfo = myType.GetProperty("MyProperty") ' Display Name propety to console. Console.WriteLine("The {0} property exists in MyClass.", myPropInfo.Name) Catch e As NullReferenceException Console.WriteLine("The property does not exist in MyClass.", e.Message.ToString()) End Try End Sub 'Main End Class 'MyTypeClass
using System; using System.Reflection; class MyClass { private int myProperty; // Declare MyProperty. public int MyProperty { get { return myProperty; } set { myProperty=value; } } } public class MyTypeClass { public static void Main(string[] args) { try { // Get the Type object corresponding to MyClass. Type myType=typeof(MyClass); // Get the PropertyInfo object by passing the property name. PropertyInfo myPropInfo = myType.GetProperty("MyProperty"); // Display the property name. Console.WriteLine("The {0} property exists in MyClass.", myPropInfo.Name); } catch(NullReferenceException e) { Console.WriteLine("The property does not exist in MyClass." + e.Message); } } }
using namespace System; using namespace System::Reflection; ref class MyClass { private: int myProperty; public: property int MyProperty { // Declare MyProperty. int get() { return myProperty; } void set( int value ) { myProperty = value; } } }; int main() { try { // Get the Type object corresponding to MyClass. Type^ myType = MyClass::typeid; // Get the PropertyInfo object by passing the property name. PropertyInfo^ myPropInfo = myType->GetProperty( "MyProperty" ); // Display the property name. Console::WriteLine( "The {0} property exists in MyClass.", myPropInfo->Name ); } catch ( NullReferenceException^ e ) { Console::WriteLine( "The property does not exist in MyClass. {0}", e->Message ); } }
import System.*; import System.Reflection.*; class MyClass { private int myProperty; // Declare MyProperty. /** @property */ public int get_MyProperty() { return myProperty ; }//MyProperty /** @property */ public void set_MyProperty (int value) { myProperty = value; }//MyProperty } //MyClass public class MyTypeClass{ public static void main(String[] args) { try { // Get the Type object corresponding to MyClass. Type myType = MyClass .class.ToType(); // Get the PropertyInfo object by passing the property name. PropertyInfo myPropInfo = myType.GetProperty("MyProperty"); // Display the property name. Console.WriteLine("The {0} property exists in MyClass.", myPropInfo.get_Name()); } catch (NullReferenceException e) { Console.WriteLine("The property does not exist in MyClass." + e.get_Message()); } } //main } //MyTypeClass
内部的には、このプロパティはメタデータで "Item" という名前で参照されます。したがって、リフレクションを使用して PropertyInfo を取得する場合は、正しい PropertyInfo プロパティが返されるように、この内部名を指定する必要があります。

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.GetProperty メソッド

名前 | 説明 |
---|---|
Type.GetProperty (String) | 指定した名前のパブリック プロパティを検索します。 .NET Compact Framework によってサポートされています。 |
Type.GetProperty (String, BindingFlags) | 指定したバインディング制約を使用して、指定したプロパティを検索します。 .NET Compact Framework によってサポートされています。 |
Type.GetProperty (String, Type) | 指定した名前および戻り値の型を持つパブリック プロパティを検索します。 .NET Compact Framework によってサポートされています。 |
Type.GetProperty (String, Type[]) | 指定したパブリック プロパティのうち、指定した引数型と一致するパラメータが設定されているものを検索します。 |
Type.GetProperty (String, Type, Type[]) | 指定したパブリック プロパティのうち、指定した引数型と一致するパラメータが設定されているものを検索します。 .NET Compact Framework によってサポートされています。 |
Type.GetProperty (String, Type, Type[], ParameterModifier[]) | 指定したパブリック プロパティのうち、指定した引数の型および修飾子と一致するパラメータが設定されているものを検索します。 .NET Compact Framework によってサポートされています。 |
Type.GetProperty (String, BindingFlags, Binder, Type, Type[], ParameterModifier[]) | 指定したバインディング制約を使用して、指定した引数の型および修飾子と一致するパラメータが設定された指定のプロパティを検索します。 .NET Compact Framework によってサポートされています。 |

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

Dim instance As Type Dim name As String Dim bindingAttr As BindingFlags Dim returnValue As PropertyInfo returnValue = instance.GetProperty(name, bindingAttr)
- bindingAttr
検索の実行方法を指定する 1 つ以上の BindingFlags から成るビット マスク。
または
null 参照 (Visual Basic では Nothing) を返す 0。
指定した要件と一致するプロパティが存在する場合は、そのプロパティを表す PropertyInfo オブジェクト。それ以外の場合は null 参照 (Visual Basic では Nothing)。


types 配列と modifiers 配列の長さが同じです。types 配列で指定するパラメータには、modifiers 配列で指定されている pdIn、pdOut、pdLcid、pdRetval、pdOptional、pdHasDefault の各属性を設定できます。これらの属性は、それぞれ [In]、[Out]、[lcid]、[retval]、[optional]、およびパラメータが既定値を持つかどうかを指定する値を表します。パラメータに関連付けられた属性はメタデータに格納され、相互運用性を拡張します。
次の 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 がジェネリック型またはジェネリック メソッドの定義の型パラメータを表している場合、このメソッドはクラス制約のプロパティを検索します。

ユーザー定義クラスの型と、そのクラスのプロパティを取得して、指定したバインディング制約に一致するプロパティ名を表示する例を次に示します。
Imports System Imports System.Reflection Module Module1 Public Class MyClass1 Private myProperty1 As Integer ' Declare MyProperty. Public Property MyProperty() As Integer Get Return myProperty1 End Get Set(ByVal Value As Integer) myProperty1 = Value End Set End Property Public Shared Sub Main() Try ' Get a Type object corresponding to MyClass. Dim myType As Type = GetType(MyClass1) ' Get a PropertyInfo object by passing property name and specifying BindingFlags. Dim myPropInfo As PropertyInfo = myType.GetProperty("MyProperty", BindingFlags.Public Or BindingFlags.Instance) ' Display the Name property. Console.WriteLine("{0} is a property of MyClass.", myPropInfo.Name) Catch e As NullReferenceException Console.WriteLine("MyProperty does not exist in MyClass.", e.Message.ToString()) End Try End Sub 'Main End Class 'MyClass1 End Module 'Module1
using System; using System.Reflection; class MyClass { private int myProperty; // Declare MyProperty. public int MyProperty { get { return myProperty; } set { myProperty=value; } } } public class MyTypeClass { public static void Main(string[] args) { try { // Get Type object of MyClass. Type myType=typeof(MyClass); // Get the PropertyInfo by passing the property name and specifying the BindingFlags. PropertyInfo myPropInfo = myType.GetProperty("MyProperty", BindingFlags.Public | BindingFlags.Instance); // Display Name propety to console. Console.WriteLine("{0} is a property of MyClass.", myPropInfo.Name); } catch(NullReferenceException e) { Console.WriteLine("MyProperty does not exist in MyClass." +e.Message); } } }
using namespace System; using namespace System::Reflection; ref class MyClass { private: int myProperty; public: property int MyProperty { // Declare MyProperty. int get() { return myProperty; } void set( int value ) { myProperty = value; } } }; int main() { try { // Get Type object of MyClass. Type^ myType = MyClass::typeid; // Get the PropertyInfo by passing the property name and specifying the BindingFlags. PropertyInfo^ myPropInfo = myType->GetProperty( "MyProperty", static_cast<BindingFlags>(BindingFlags::Public | BindingFlags::Instance) ); // Display Name propety to console. Console::WriteLine( "{0} is a property of MyClass.", myPropInfo->Name ); } catch ( NullReferenceException^ e ) { Console::WriteLine( "MyProperty does not exist in MyClass. {0}", e->Message ); } }
import System.*; import System.Reflection.*; class MyClass { private int myProperty; // Declare MyProperty. /** @property */ public int get_MyProperty() { return myProperty; } //MyProperty /** @property */ public void set_MyProperty(int value) { myProperty = value; } //MyProperty } //MyClass public class MyTypeClass { public static void main(String[] args) { try { // Get Type object of MyClass. Type myType = MyClass.class.ToType(); // Get the PropertyInfo by passing the property name and // specifying the BindingFlags. PropertyInfo myPropInfo = myType.GetProperty("MyProperty", BindingFlags.Public | BindingFlags.Instance); // Display Name propety to console. Console.WriteLine("{0} is a property of MyClass.", myPropInfo.get_Name()); } catch (NullReferenceException e) { Console.WriteLine("MyProperty does not exist in MyClass." + e.get_Message()); } } //main } //MyTypeClass

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.GetProperty メソッド

名前 | 説明 |
---|---|
_Type.GetProperty (String) | COM オブジェクトに、Type.GetProperty メソッドへのバージョンに依存しないアクセスが用意されています。 |
_Type.GetProperty (String, BindingFlags) | COM オブジェクトに、Type.GetProperty メソッドへのバージョンに依存しないアクセスが用意されています。 |
_Type.GetProperty (String, Type) | COM オブジェクトに、Type.GetProperty メソッドへのバージョンに依存しないアクセスが用意されています。 |
_Type.GetProperty (String, Type[]) | COM オブジェクトに、Type.GetProperty メソッドへのバージョンに依存しないアクセスが用意されています。 |
_Type.GetProperty (String, Type, Type[]) | COM オブジェクトに、Type.GetProperty メソッドへのバージョンに依存しないアクセスが用意されています。 |
_Type.GetProperty (String, Type, Type[], ParameterModifier[]) | COM オブジェクトに、Type.GetProperty メソッドへのバージョンに依存しないアクセスが用意されています。 |
_Type.GetProperty (String, BindingFlags, Binder, Type, Type[], ParameterModifier[]) | COM オブジェクトに、Type.GetProperty メソッドへのバージョンに依存しないアクセスが用意されています。 |

Weblioに収録されているすべての辞書からType.GetPropertyを検索する場合は、下記のリンクをクリックしてください。

- Type.GetPropertyのページへのリンク