Type.GetProperties メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Type.GetProperties メソッドの意味・解説 

Type.GetProperties メソッド (BindingFlags)

派生クラスによってオーバーライドされた場合指定したバインディング制約使用して現在の Typeプロパティ検索します

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

Public MustOverride Function
 GetProperties ( _
    bindingAttr As BindingFlags _
) As PropertyInfo()
Dim instance As Type
Dim bindingAttr As BindingFlags
Dim returnValue As PropertyInfo()

returnValue = instance.GetProperties(bindingAttr)
public abstract PropertyInfo[] GetProperties (
    BindingFlags bindingAttr
)
public:
virtual array<PropertyInfo^>^ GetProperties (
    BindingFlags bindingAttr
) abstract
public abstract PropertyInfo[] GetProperties (
    BindingFlags bindingAttr
)
public abstract function GetProperties (
    bindingAttr : BindingFlags
) : PropertyInfo[]

パラメータ

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 修飾フラグは、検索方法変更するために使用できます

詳細については、「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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Type クラス
Type メンバ
System 名前空間
PropertyInfo
BindingFlags
DefaultBinder
GetProperty

Type.GetProperties メソッド


Type.GetProperties メソッド ()

現在の Typeすべてのパブリック プロパティ返します

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

Public Function GetProperties As
 PropertyInfo()
Dim instance As Type
Dim returnValue As PropertyInfo()

returnValue = instance.GetProperties
public PropertyInfo[] GetProperties ()
public:
virtual array<PropertyInfo^>^ GetProperties () sealed
public final PropertyInfo[] GetProperties ()
public final function GetProperties () : PropertyInfo[]

戻り値
現在の Typeすべてのパブリック プロパティを表す PropertyInfo オブジェクト配列。 または 現在の Typeパブリック プロパティ存在しない場合は、PropertyInfo 型の空の配列

解説解説

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

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

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

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

現在の 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());
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

_Type.GetProperties メソッド

COM オブジェクトに、System.Type.GetProperties メソッドへのバージョン依存しないアクセス用意されています。
オーバーロードの一覧オーバーロードの一覧

名前 説明
_Type.GetProperties () COM オブジェクトに、Type.GetProperties メソッドへのバージョン依存しないアクセス用意されています。
_Type.GetProperties (BindingFlags) COM オブジェクトに、Type.GetProperties メソッドへのバージョン依存しないアクセス用意されています。
参照参照

関連項目

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


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

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

辞書ショートカット

すべての辞書の索引

「Type.GetProperties メソッド」の関連用語

Type.GetProperties メソッドのお隣キーワード
検索ランキング

   

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



Type.GetProperties メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS