Este artículo se tradujo automáticamente. Para ver el artículo en inglés, active la casilla Inglés. Además, puede mostrar el texto en inglés en una ventana emergente si mueve el puntero del mouse sobre el texto.
Traducción
Inglés

Método Type.GetProperties ()

 

Publicado: octubre de 2016

Devuelve todas las propiedades públicas del objeto Type actual.

Espacio de nombres:   System
Ensamblado:  mscorlib (en mscorlib.dll)

public PropertyInfo[] GetProperties()

Valor devuelto

Type: System.Reflection.PropertyInfo[]

Matriz de objetos PropertyInfo que representa todas las propiedades públicas del objeto Type actual.

o bien

Matriz vacía de tipo PropertyInfo si el objeto Type actual no tiene propiedades públicas.

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
Disponible desde 1.1
Biblioteca de clases portable
Se admite en: plataformas portátiles de .NET
Silverlight
Disponible desde 2.0
Windows Phone Silverlight
Disponible desde 7.0
Volver al principio
Mostrar: