Dieser Artikel wurde maschinell übersetzt. Wenn Sie die englische Version des Artikels anzeigen möchten, aktivieren Sie das Kontrollkästchen Englisch. Sie können den englischen Text auch in einem Popupfenster anzeigen, indem Sie den Mauszeiger über den Text bewegen.
Übersetzung
Englisch

Type.GetProperties-Methode ()

 

Gibt sämtliche öffentlichen Eigenschaften des aktuellen Type zurück.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

public PropertyInfo[] GetProperties()

Rückgabewert

Type: System.Reflection.PropertyInfo[]

Ein Array von PropertyInfo-Objekten, die alle öffentlichen Eigenschaften des aktuellen Type darstellen.

- oder -

Ein leeres Array vom PropertyInfo-Typ, wenn der aktuelle Type keine öffentlichen Eigenschaften besitzt.

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
Verfügbar seit 1.1
Portable Class Library
Unterstützt in: portable .NET platforms
Silverlight
Verfügbar seit 2.0
Windows Phone Silverlight
Verfügbar seit 7.0
Zurück zum Anfang
Anzeigen: