System.Type.GetProperties Method

When overridden in a derived class, searches for the properties of the current Type, using the specified binding constraints.

Syntax

public abstract System.Reflection.PropertyInfo[] GetProperties (System.Reflection.BindingFlags bindingAttr)

Parameters

bindingAttr
A bitmask comprised of one or more System.Reflection.BindingFlags that specify how the search is conducted.

Returns

An array of System.Reflection.PropertyInfo objects representing all properties of the current Type that match the specified binding constraints.

-or-

An empty array of type System.Reflection.PropertyInfo, if the current Type does not have properties, or if none of the properties match the binding constraints.

Remarks

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 System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Static (in Visual Basic, combine the values using Or) to get it.

The Type.GetProperties(System.Reflection.BindingFlags) 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 System.Reflection.BindingFlags filter flags can be used to define which nested types to include in the search:

  • You must specify either BindingFlags.Instance or BindingFlags.Static in order to get a return.

  • Specify BindingFlags.Public to include public properties in the search.

  • Specify BindingFlags.NonPublic to include non-public properties (that is, private, internal, and protected properties) in the search. Only protected and internal properties on base classes are returned; private properties on base classes are not returned.

  • Specify BindingFlags.FlattenHierarchy to include public and protected static members up the hierarchy; private static members in inherited classes are not included.

The following System.Reflection.BindingFlags modifier flags can be used to change how the search works:

  • BindingFlags.DeclaredOnly to search only the properties declared on the Type, not properties that were simply inherited.

See System.Reflection.BindingFlags for more information.

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 System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Static (in Visual Basic, combine the values using Or) to get it.

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

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

Permissions

TypeReason
System.Security.Permissions.ReflectionPermissionRequires permission to retrieve information on non-public members of types in loaded assemblies. See System.Security.Permissions.ReflectionPermissionFlag.TypeInformation.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0