Object
MemberInfo
PropertyInfo
mscorlib
Reflection
Provides access to property metadata.
A property is a named aspect of an object's state whose value is typically accessible throughgetandsetaccessors. [Note: Properties can be read-only, in which case thesetaccessor is not available.]
Several methods in this class assume that the
GetandSetaccessors of a property have certain formats. The signatures of the accessors are required to match the following conventions:
If this format is not followed, the behavior of the System.Reflection.PropertyInfo.GetValue(System.Object,System.Object[]) and System.Reflection.PropertyInfo.SetValue(System.Object,System.Object,System.Object[]) methods is undefined.
- The return type of the
Getaccessor and the last argument of theSetaccessor are required to be identical to the type of the property reflected by the current instance.- The
GetandSetaccessors are required to have the same number, type, and order of indices.
System.Reflection Namespace
PropertyInfo Constructors
PropertyInfo Methods
PropertyInfo.GetAccessors(bool) Method
PropertyInfo.GetAccessors() Method
PropertyInfo.GetGetMethod(bool) Method
PropertyInfo.GetGetMethod() Method
PropertyInfo.GetIndexParameters Method
PropertyInfo.GetSetMethod(bool) Method
PropertyInfo.GetSetMethod() Method
PropertyInfo.GetValue(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo) Method
PropertyInfo.GetValue(System.Object, System.Object[]) Method
PropertyInfo.SetValue(System.Object, System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo) Method
PropertyInfo.SetValue(System.Object, System.Object, System.Object[]) Method
PropertyInfo Properties
PropertyInfo.Attributes Property
PropertyInfo.CanRead Property
PropertyInfo.CanWrite Property
PropertyInfo.PropertyType Property
Constructs a new instance of the PropertyInfo class.
System.Reflection.PropertyInfo Class, System.Reflection Namespace
Returns an array whose elements reflect the public and, if specified, non-publicGet,Set, and other accessors of the property reflected by the current instance.
- nonPublic
- A Boolean value that indicates whether non-public accessors will be included in the return value. Specify
trueto include the non-public accessors; otherwise, specifyfalse.
An array of MethodInfo objects whose elements reflect theGet,Set, and other accessors of the property reflected by the current instance. If nonPublic istrue, this array contains public and non-public accessors. If nonPublic isfalse, this array contains only public accessors. If no accessors with the specified visibility are found, returns an array with zero elements.
[Behaviors: As described above.]
System.Reflection.PropertyInfo Class, System.Reflection Namespace
Returns an array whose elements reflect the publicGet,Set, and other accessors of the property reflected by the current instance.
An array of MethodInfo objects that reflect the publicGet,Set, and other accessors of the property reflected by the current instance, if found; otherwise, returns an array with zero elements.
This method is equivalent to System.Reflection.PropertyInfo.GetAccessors(false).
System.Reflection.PropertyInfo Class, System.Reflection Namespace
Returns the public or, if specified, non-publicGetaccessor for the property reflected by the current instance.
- nonPublic
- A Boolean value that indicates whether non-public
Getaccessors will be included in the return value. Specifytrueto include non-public accessors; otherwise, specifyfalse.
If nonPublic istrue, returns a MethodInfo instance that reflects theGetaccessor for the property reflected by the current instance if that accessor exists. If nonPublic isfalseand theGetaccessor is non-public, or nonPublic istruebut noGetaccessor exists for the property reflected by the current instance, returnsnull.
Exception Type Condition MethodAccessException nonPublic is true, theGetaccessor for the property reflected by the current instance is non-public, and the caller does not have ReflectionPermission to reflect on non-public methods.
[Behaviors: As described above.]
System.Reflection.PropertyInfo Class, System.Reflection Namespace
Returns the publicGetaccessor for the property reflected by the current instance.
A MethodInfo instance that reflects the publicGetaccessor for the property reflected by the current instance. Returnsnullif no publicGetaccessor exists.
System.Reflection.PropertyInfo Class, System.Reflection Namespace
Returns an array of the indexers of the property reflected by the current instance.
An array of ParameterInfo objects that reflect the indexers of the property reflected by the current instance. If no indexers exist for the property reflected by the current instance, returns an array with zero elements.
Exception Type Condition MethodAccessException The property reflected by the current instance is visible, but its GetandSetaccessors are not, and the caller does not have ReflectionPermission.
[Behaviors: As described above.]
System.Reflection.PropertyInfo Class, System.Reflection Namespace
Returns the public or, if specified, non-publicSetaccessor for the property reflected by the current instance.
- nonPublic
- A Boolean value that indicates whether non-public
Setaccessors are included in the return value. Specifytrueif non-public accessors are to be included; otherwise, specifyfalse.
If nonPublic istrue, returns a MethodInfo instance that reflects theSetaccessor for the property reflected by the current instance if that accessor exists. If nonPublic isfalseand theSetaccessor is non-public, or nonPublic istruebut noSetaccessor exists for the property reflected by the current instance, returnsnull.
Exception Type Condition MethodAccessException nonPublic is true, theSetaccessor for the property reflected by the current instance is non-public, and the caller does not have ReflectionPermission to reflect on non-public methods.
[Behaviors: As described above.]
System.Reflection.PropertyInfo Class, System.Reflection Namespace
Returns the publicSetaccessor for the property reflected by the current instance.
A MethodInfo instance that reflects the publicSetaccessor for the property reflected by the current instance. Returnsnullif no publicSetaccessor exists.
This method is equivalent to System.Reflection.PropertyInfo.GetSetMethod(false).
System.Reflection.PropertyInfo Class, System.Reflection Namespace
Returns the value of the property that is reflected by the current instance in the specified object and corresponds to the specified criteria.
- obj
- The object whose property value is returned. Specify
nullto invoke a staticGetaccessor on the property reflected by the current instance.- invokeAttr
- A BindingFlags value that controls the binding process. [Note: Specify System.Reflection.BindingFlags.Public or System.Reflection.BindingFlags.NonPublic, and System.Reflection.BindingFlags.Instance or System.Reflection.BindingFlags.Static; or this method will not invoke any
getaccessors of the property reflected by the current instance.]
- binder
- A Binder that enables the binding, coercion of argument types, invocation of members, and retrieval of MemberInfo objects via reflection. If binder is
null, the default binder is used.- index
- An array of objects that is an index or values for indexed properties. This value is required to be
nullfor non-indexed properties.- culture
- The only defined value for this parameter is
null.
A Object that contains the property value for obj .
Exception Type Condition ArgumentException index does not contain the exact type of arguments needed. The
Getaccessor of the property reflected by the current instance was not found.
MethodAccessException The Getaccessor of the property reflected by the current instance is non-public and the caller does not have ReflectionPermission to reflect on non-public methods.TargetException The property reflected by the current instance is non-static, and obj is nullor is of a type that does not implement the property reflected by the current instance.TargetParameterCountException The current instance reflects an indexer and index.Length does not equal the rank of the indexer. 
[Behaviors: As described above.]
System.Reflection.PropertyInfo Class, System.Reflection Namespace
Returns the value of the property reflected by the current instance in the specified object, using the specified index values.
- obj
- The object whose property value will be returned. Specify
nullto invoke a staticGetaccessor of a property.- index
- An array of objects that is an index of values for indexed properties. This value is required to be
nullfor non-indexed properties.
A Object that contains the property value for obj .
Exception Type Condition ArgumentException index does not contain the exact type of arguments needed. -or-
The
Getaccessor of the property reflected by the current instance is not found.
MethodAccessException The Getaccessor of the property reflected by the current instance is non-public and the caller does not have ReflectionPermission to reflect on non-public methods.TargetException The property reflected by the current instance is non-static, and obj is nullor is of a type that does not implement the property reflected by the current instance.TargetParameterCountException The current instance reflects an indexer and index.Length does not equal the rank of the indexer. 
[Behaviors: As described above.]
System.Reflection.PropertyInfo Class, System.Reflection Namespace
Sets the value of the property that is reflected by the current instance on the specified objects and corresponds to the specified properties.
- obj
- The object whose property value is returned. Specify
nullto invoke a staticSetaccessor on the property reflected by the current instance.- value
- A object that contains the new value for the property.
- invokeAttr
- A BindingFlags value that controls the binding process. [Note: Specify System.Reflection.BindingFlags.Public or System.Reflection.BindingFlags.NonPublic, and System.Reflection.BindingFlags.Instance or System.Reflection.BindingFlags.Static; otherwise, this method will not invoke any
Setaccessors of the property reflected by the current instance.]
- binder
- A Binder that enables the binding, coercion of argument types, invocation of members, and retrieval of MemberInfo objects via reflection. If binder is
null, the default binder is used.- index
- An array of objects that is an index or values for indexed properties. This value is required to be
nullfor non-indexed properties.- culture
- The only defined value for this parameter is
null.
Exception Type Condition ArgumentException The index array does not contain the exact type of arguments needed. The Setaccessor of the property reflected by the current instance is not found.
TargetException The property reflected by the current instance is non-static, and obj is nullor is of a type that does not implement the property reflected by the current instance.MethodAccessException The Setaccessor of the property reflected by the current instance is non-public and the caller does not have ReflectionPermission to reflect on non-public methods.TargetParameterCountException The current instance reflects an indexer and index.Length does not equal the rank of the indexer. 
[Behaviors: As described above.]
System.Reflection.PropertyInfo Class, System.Reflection Namespace
Sets the value of the property reflected by the current instance on the specified object, using the specified index values.
- obj
- The object whose property value is returned. Specify
nullto invoke a staticSetaccessor on the property reflected by the current instance.- value
- A object that contains the new value for the property.
- index
- An array of objects that is an index or values for indexed properties. This value is required to be
nullfor non-indexed properties.
Exception Type Condition ArgumentException index does not contain the exact type of arguments needed. -or-
The
Setaccessor of the property reflected by the current instance was not found.
MethodAccessException The Setaccessor of the property reflected by the current instance is non-public and the caller does not have ReflectionPermission to reflect on non-public methods.TargetException The property reflected by the current instance is non-static, and obj is nullor is of a type that does not implement the property reflected by the current instance.TargetParameterCountException The current instance reflects an indexer and index.Length does not equal the rank of the indexer. 
[Behaviors: As described above.]
System.Reflection.PropertyInfo Class, System.Reflection Namespace
public abstract PropertyAttributes Attributes { get; }
Gets the attributes of the property reflected by the current instance.
A PropertyAttributes value that specifies the attributes of the property reflected by the current instance.
[Behaviors: This property is read-only.This property gets a PropertyAttributes value that indicates the attributes set in the metadata of the property reflected by the current instance.
]
[Usage: Use this property to determine if the property reflected by the current instance has a special name or a default value.]
System.Reflection.PropertyInfo Class, System.Reflection Namespace
public abstract bool CanRead { get; }
Gets a Boolean value indicating whether the property reflected by the current instance has aGetaccessor.
trueif the property reflected by the current instance has aGetaccessor; otherwise,false.
[Behaviors: This property is read-only.]
System.Reflection.PropertyInfo Class, System.Reflection Namespace
public abstract bool CanWrite { get; }
Gets a Boolean value indicating whether the property reflected by the current instance has aSetaccessor.
trueif the property reflected by the current instance has aSetaccessor; otherwise,false.
[Behaviors: This property is read-only.]
System.Reflection.PropertyInfo Class, System.Reflection Namespace
public abstract Type PropertyType { get; }
Gets the type of the property reflected by the current instance.
A Type that represents the type of the property reflected by the current instance.
[Behaviors: This property is read-only.]
System.Reflection.PropertyInfo Class, System.Reflection Namespace