次の方法で共有


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

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

Overloads Public Function GetProperty( _
   ByVal name As String, _   ByVal returnType As Type _) As PropertyInfo
[C#]
public PropertyInfo GetProperty(stringname,TypereturnType);
[C++]
public: PropertyInfo* GetProperty(String* name,Type* returnType);
[JScript]
public function GetProperty(
   name : String,returnType : Type) : PropertyInfo;

パラメータ

  • name
    取得するパブリック プロパティの名前を格納している String
  • returnType
    プロパティの戻り値の型。

戻り値

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

例外

例外の種類 条件
AmbiguousMatchException 指定した名前のプロパティが 2 つ以上存在します。
ArgumentNullException name が null 参照 (Visual Basic では Nothing) です。

解説

name の検索では大文字と小文字が区別されます。

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

使用例

1 つのプロパティを持つクラスを定義し、そのプロパティの名前と型を取得する例を次に示します。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard

参照

Type クラス | Type メンバ | System 名前空間 | Type.GetProperty オーバーロードの一覧 | PropertyInfo | String | DefaultBinder | ReflectionPermission | GetPropertyImpl | GetProperties