_Type.GetPropertyとは? わかりやすく解説

Type.GetProperty メソッド (String, Type, Type[], ParameterModifier[])

指定したパブリック プロパティのうち、指定した引数の型および修飾子一致するパラメータ設定されているものを検索します

名前空間: System
アセンブリ: 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

パラメータ

name

取得するパブリック プロパティの名前を格納している String

returnType

プロパティ戻り値の型。

types

取得するインデックス付きプロパティ対すパラメータ数値順序、および型を表す Type オブジェクト配列

または

インデックス付けされていないプロパティ取得するための、Type 型の空の配列 (Type[] types = new Type[0])。

modifiers

types 配列内の対応する要素関連付けられている属性を表す ParameterModifier オブジェクト配列既定バインダは、このパラメータ処理しません。

戻り値
指定した要件一致するパブリック プロパティ存在する場合は、そのパブリック プロパティを表す PropertyInfo オブジェクトそれ以外場合null 参照 (Visual Basic では Nothing)。

例外例外
例外種類条件

AmbiguousMatchException

指定した名前を持ち指定した引数の型および修飾子一致するプロパティ2 つ以上存在します

ArgumentNullException

namenull 参照 (Visual Basic では Nothing) です。

または

typesnull 参照 (Visual Basic では Nothing) です。

または

types1 つ要素null 参照 (Visual Basic では Nothing) です。

ArgumentException

types多次元です。

または

modifiers多次元です。

または

typesmodifiers長さ異なります

解説解説

既定バインダ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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Type クラス
Type メンバ
System 名前空間
PropertyInfo
String クラス
DefaultBinder
ParameterModifier
ReflectionPermission
GetPropertyImpl
GetProperties

Type.GetProperty メソッド (String, Type)

指定した名前および戻り値の型を持つパブリック プロパティ検索します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Function GetProperty ( _
    name As String, _
    returnType As Type _
) As PropertyInfo
Dim instance As Type
Dim name As String
Dim returnType As Type
Dim returnValue As PropertyInfo

returnValue = instance.GetProperty(name, returnType)
public PropertyInfo GetProperty (
    string name,
    Type returnType
)
public:
virtual PropertyInfo^ GetProperty (
    String^ name, 
    Type^ returnType
) sealed
public final PropertyInfo GetProperty (
    String name, 
    Type returnType
)
public final function GetProperty (
    name : String, 
    returnType : Type
) : PropertyInfo

パラメータ

name

取得するパブリック プロパティの名前を格納している String

returnType

プロパティ戻り値の型。

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

例外例外
例外種類条件

AmbiguousMatchException

指定した名前のプロパティ2 つ以上存在します

ArgumentNullException

namenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Type クラス
Type メンバ
System 名前空間
PropertyInfo
String クラス
DefaultBinder
ReflectionPermission
GetPropertyImpl
GetProperties

Type.GetProperty メソッド (String, Type[])

指定したパブリック プロパティのうち、指定した引数型と一致するパラメータ設定されているものを検索します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

例外例外
例外種類条件

AmbiguousMatchException

指定した名前と、指定した引数型に一致するパラメータを持つプロパティ2 つ以上存在します

ArgumentNullException

namenull 参照 (Visual Basic では Nothing) です。

または

typesnull 参照 (Visual Basic では Nothing) です。

または

types1 つ要素null 参照 (Visual Basic では Nothing) です。

ArgumentException

types多次元です。

解説解説
使用例使用例

ユーザー定義クラス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返されるように、この内部名指定する必要があります

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Type クラス
Type メンバ
System 名前空間
PropertyInfo
String クラス
DefaultBinder
ReflectionPermission
GetPropertyImpl
GetProperties

Type.GetProperty メソッド (String, BindingFlags, Binder, Type, Type[], ParameterModifier[])

指定したバインディング制約使用して指定した引数の型および修飾子一致するパラメータ設定され指定プロパティ検索します

名前空間: System
アセンブリ: 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

パラメータ

name

取得するプロパティの名前を格納している String

bindingAttr

検索実行方法指定する 1 つ上の BindingFlags から成るビット マスク

または

null 参照 (Visual Basic では Nothing) を返す 0。

binder

一連のプロパティ定義しバインディング有効にする Binder オブジェクトバインディングには、オーバーロードされたメソッド選択引数の型の強制変換リフレクションによるメンバ呼び出しなどが含まれます。

または

DefaultBinder を使用する場合null 参照 (Visual Basic では Nothing)。

returnType

プロパティ戻り値の型。

types

取得するインデックス付きプロパティ対すパラメータ数値順序、および型を表す Type オブジェクト配列

または

インデックス付けされていないプロパティ取得するための、Type 型の空の配列 (Type[] types = new Type[0])。

modifiers

types 配列内の対応する要素関連付けられている属性を表す ParameterModifier オブジェクト配列既定バインダは、このパラメータ処理しません。

戻り値
指定した要件一致するプロパティ存在する場合は、そのプロパティを表す PropertyInfo オブジェクトそれ以外場合null 参照 (Visual Basic では Nothing)。

例外例外
例外種類条件

AmbiguousMatchException

指定した名前を持ち指定したバインディング制約一致するプロパティ2 つ以上存在します

ArgumentNullException

namenull 参照 (Visual Basic では Nothing) です。

または

typesnull 参照 (Visual Basic では Nothing) です。

または

types1 つ要素null 参照 (Visual Basic では Nothing) です。

ArgumentException

types多次元です。

または

modifiers多次元です。

または

typesmodifiers長さ異なります

解説解説

既定バインダParameterModifier (modifiers パラメータ) を処理しませんが、System.Reflection.Binder 抽象クラス使用してmodifiers処理するカスタム バインダ記述できますParameterModifier は、COM 相互運用機能によって呼び出すときだけに使用され参照渡しされるパラメータだけが処理されます。

型に対すリフレクション時に Get メソッドによって返される基本クラスメンバ次の表に示します

  1. 名前と署名による隠ぺいでは、カスタム修飾子戻り値の型、パラメータの型、sentinel、およびアンマネージ呼び出し規約含めて署名すべての部分判断対象となります。これはバイナリ比較です。

  2. リフレクション場合プロパティおよびイベントは名前と署名によって隠ぺいされています。基本クラスget アクセサset アクセサ両方を持つプロパティがあり、派生クラスには get アクセサしかない場合派生クラスプロパティにより基本クラスプロパティ隠ぺいされ、基本クラスset アクセサにはアクセスできません。

  3. カスタム属性は、共通型システム一部ではありません。

types 配列modifiers 配列長さが同じです。types 配列指定するパラメータには、modifiers 配列指定されている pdIn、pdOut、pdLcid、pdRetval、pdOptional、pdHasDefault の各属性設定できます。これらの属性は、それぞれ [In]、[Out]、[lcid]、[retval]、[optional]、およびパラメータ既定値を持つかどうか指定する値を表しますパラメータ関連付けられた属性メタデータ格納され相互運用性拡張します。

次の BindingFlags フィルタ フラグは、検索対象含めプロパティ定義するために使用できます

次の BindingFlags 修飾フラグは、検索方法変更するために使用できます

詳細については、「System.Reflection.BindingFlags」を参照してください

要求された型がパブリックではなく呼び出し元に現在のアセンブリ外の非パブリック オブジェクトリフレクションするための ReflectionPermission がない場合、このメソッドnull 参照 (Visual Basic では Nothing) を返します

現在の T:System.Type が構築ジェネリック型表している場合、このメソッドは、型パラメータ適切な型の引数置き換えて PropertyInfo返します

現在の Typeジェネリック型またはジェネリック メソッドの定義の型パラメータ表している場合、このメソッドクラス制約のプロパティ検索します

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Type クラス
Type メンバ
System 名前空間
PropertyInfo
String クラス
BindingFlags
Binder
DefaultBinder
ParameterModifier
ReflectionPermission
GetPropertyImpl
GetProperties

Type.GetProperty メソッド (String, Type, Type[])

指定したパブリック プロパティのうち、指定した引数型と一致するパラメータ設定されているものを検索します

名前空間: System
アセンブリ: 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 PropertyInfo GetProperty (
    string name,
    Type returnType,
    Type[] types
)
public:
virtual PropertyInfo^ GetProperty (
    String^ name, 
    Type^ returnType, 
    array<Type^>^ types
) sealed
public final PropertyInfo GetProperty (
    String name, 
    Type returnType, 
    Type[] types
)
public final function GetProperty (
    name : String, 
    returnType : Type, 
    types : Type[]
) : PropertyInfo

パラメータ

name

取得するパブリック プロパティの名前を格納している String

returnType

プロパティ戻り値の型。

types

取得するインデックス付きプロパティ対すパラメータ数値順序、および型を表す Type オブジェクト配列

または

インデックス付けされていないプロパティ取得するための、Type 型の空の配列 (Type[] types = new Type[0])。

戻り値
指定した引数型と一致するパラメータ設定されているパブリック プロパティ存在する場合は、そのパブリック プロパティを表す PropertyInfo オブジェクトそれ以外場合null 参照 (Visual Basic では Nothing)。

例外例外
例外種類条件

AmbiguousMatchException

指定した名前と、指定した引数型に一致するパラメータを持つプロパティ2 つ以上存在します

ArgumentNullException

namenull 参照 (Visual Basic では Nothing) です。

または

typesnull 参照 (Visual Basic では Nothing) です。

または

types1 つ要素null 参照 (Visual Basic では Nothing) です。

ArgumentException

types多次元です。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Type クラス
Type メンバ
System 名前空間
PropertyInfo
String クラス
DefaultBinder
ReflectionPermission
GetPropertyImpl
GetProperties

Type.GetProperty メソッド (String)

指定した名前のパブリック プロパティ検索します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Function GetProperty ( _
    name As String _
) As PropertyInfo
Dim instance As Type
Dim name As String
Dim returnValue As PropertyInfo

returnValue = instance.GetProperty(name)
public PropertyInfo GetProperty (
    string name
)
public:
virtual PropertyInfo^ GetProperty (
    String^ name
) sealed
public final PropertyInfo GetProperty (
    String name
)
public final function GetProperty (
    name : String
) : PropertyInfo

パラメータ

name

取得するパブリック プロパティの名前を格納している String

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

例外例外
例外種類条件

AmbiguousMatchException

指定した名前のプロパティ2 つ以上存在します

ArgumentNullException

namenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

ユーザー定義クラス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 プロパティ返されるように、この内部名指定する必要があります

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Type クラス
Type メンバ
System 名前空間
PropertyInfo
String クラス
DefaultBinder
ReflectionPermission
GetPropertyImpl
GetProperties

Type.GetProperty メソッド

現在の Type特定のプロパティ取得します
オーバーロードの一覧オーバーロードの一覧

名前 説明
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 クラス
Type メンバ
System 名前空間
PropertyInfo
String クラス
DefaultBinder
ReflectionPermission
GetPropertyImpl
GetProperties

Type.GetProperty メソッド (String, BindingFlags)

指定したバインディング制約使用して指定したプロパティ検索します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Function GetProperty ( _
    name As String, _
    bindingAttr As BindingFlags _
) As PropertyInfo
Dim instance As Type
Dim name As String
Dim bindingAttr As BindingFlags
Dim returnValue As PropertyInfo

returnValue = instance.GetProperty(name, bindingAttr)
public PropertyInfo GetProperty (
    string name,
    BindingFlags bindingAttr
)
public:
virtual PropertyInfo^ GetProperty (
    String^ name, 
    BindingFlags bindingAttr
) sealed
public final PropertyInfo GetProperty (
    String name, 
    BindingFlags bindingAttr
)
public final function GetProperty (
    name : String, 
    bindingAttr : BindingFlags
) : PropertyInfo

パラメータ

name

取得するプロパティの名前を格納している String

bindingAttr

検索実行方法指定する 1 つ上の BindingFlags から成るビット マスク

または

null 参照 (Visual Basic では Nothing) を返す 0。

戻り値
指定した要件一致するプロパティ存在する場合は、そのプロパティを表す PropertyInfo オブジェクトそれ以外場合null 参照 (Visual Basic では Nothing)。

例外例外
例外種類条件

AmbiguousMatchException

指定した名前を持ち指定したバインディング制約一致するプロパティ2 つ以上存在します

ArgumentNullException

namenull 参照 (Visual Basic では Nothing) です。

解説解説

types 配列modifiers 配列長さが同じです。types 配列指定するパラメータには、modifiers 配列指定されている pdIn、pdOut、pdLcid、pdRetval、pdOptional、pdHasDefault の各属性設定できます。これらの属性は、それぞれ [In]、[Out]、[lcid]、[retval]、[optional]、およびパラメータ既定値を持つかどうか指定する値を表しますパラメータ関連付けられた属性メタデータ格納され相互運用性拡張します。

次の BindingFlags フィルタ フラグは、検索対象含めプロパティ定義するために使用できます

次の 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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Type クラス
Type メンバ
System 名前空間
PropertyInfo
String クラス
BindingFlags
DefaultBinder
ReflectionPermission
GetPropertyImpl
GetProperties

_Type.GetProperty メソッド

COM オブジェクトに、System.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 メソッドへのバージョン依存しないアクセス用意されています。
参照参照

関連項目

_Type インターフェイス
_Type メンバ
System.Runtime.InteropServices 名前空間


このページでは「.NET Framework クラス ライブラリ リファレンス」から_Type.GetPropertyを検索した結果を表示しています。
Weblioに収録されているすべての辞書から_Type.GetPropertyを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書から_Type.GetPropertyを検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「_Type.GetProperty」の関連用語

_Type.GetPropertyのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



_Type.GetPropertyのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS