この記事は機械翻訳されています。英語版の記事を表示するには、[英語] のチェック ボックスをオンにしてください。また、テキストにマウス ポインターを合わせると、ポップアップ ウィンドウに英語のテキストを表示することもできます。
翻訳
英語

Type.GetProperties メソッド ()

 

公開日: 2016年10月

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

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

public PropertyInfo[] GetProperties()

戻り値

Type: System.Reflection.PropertyInfo[]

現在の PropertyInfo のすべてのパブリック プロパティを表す Type オブジェクトの配列。

または

現在の PropertyInfo にパブリック プロパティが存在しない場合は、Type 型の空の配列。

Calling this overload is equivalent to calling the M:System.Type.GetProperties(System.Reflection.BindingFlags) overload with a bindingAttr argument equal to BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public in C# and BindingFlags.Instance Or BindingFlags.Static Or BindingFlags.Public in Visual Basic. It returns all public instance and static properties, both those defined by the type represented by the current T:System.Type object as well as those inherited from its base types.

A property is considered public to reflection if it has at least one accessor that is public. Otherwise the property is considered private, and you must use F:System.Reflection.BindingFlags.NonPublic | F:System.Reflection.BindingFlags.Instance | F:System.Reflection.BindingFlags.Static (in Visual Basic, combine the values using Or) to get it.

The M:System.Type.GetProperties method does not return properties in a particular order, such as alphabetical or declaration order. Your code must not depend on the order in which properties are returned, because that order varies.

The following table shows what members of a base class are returned by the Get methods when reflecting on a type.

Member Type

Static

Non-Static

Constructor

No

No

Field

No

Yes. A field is always hide-by-name-and-signature.

Event

Not applicable

The common type system rule is that the inheritance is the same as that of the methods that implement the property. Reflection treats properties as hide-by-name-and-signature. See note 2 below.

Method

No

Yes. A method (both virtual and non-virtual) can be hide-by-name or hide-by-name-and-signature.

Nested Type

No

No

Property

Not applicable

The common type system rule is that the inheritance is the same as that of the methods that implement the property. Reflection treats properties as hide-by-name-and-signature. See note 2 below.

  1. Hide-by-name-and-signature considers all of the parts of the signature, including custom modifiers, return types, parameter types, sentinels, and unmanaged calling conventions. This is a binary comparison.

  2. For reflection, properties and events are hide-by-name-and-signature. If you have a property with both a get and a set accessor in the base class, but the derived class has only a get accessor, the derived class property hides the base class property, and you will not be able to access the setter on the base class.

  3. Custom attributes are not part of the common type system.

If the current T:System.Type represents a constructed generic type, this method returns the T:System.Reflection.PropertyInfo objects with the type parameters replaced by the appropriate type arguments.

If the current T:System.Type represents a type parameter in the definition of a generic type or generic method, this method searches the properties of the class constraint.

The following example demonstrates the use of the GetProperties method.

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());
}

.NET Framework
1.1 以降で使用可能
ポータブル クラス ライブラリ
サポート対象: 移植可能 .NET プラットフォーム
Silverlight
2.0 以降で使用可能
Windows Phone Silverlight
7.0 以降で使用可能
トップに戻る
表示: