public abstract class PropertyInfo : MemberInfo
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
protected PropertyInfo();
Constructs a new instance of the PropertyInfo class.
System.Reflection.PropertyInfo Class, System.Reflection Namespace
public abstract MethodInfo[] GetAccessors(bool nonPublic);
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
public MethodInfo[] GetAccessors();
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
public abstract MethodInfo GetGetMethod(bool nonPublic);
Returns the public possibly or, if specified, the non-publicGetaccessor for the property reflected by the current instance.
- nonPublic
- A Boolean value that indicates whether a non-public
Getaccessor will be returned. Specifytrueto allow a non-public accessor; 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 TypeConditionMethodAccessException nonPublic istrue, 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
public MethodInfo GetGetMethod();
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
public abstract ParameterInfo[] GetIndexParameters();
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 TypeConditionMethodAccessException The property reflected by the current instance is visible, but itsGetandSetaccessors are not, and the caller does not have ReflectionPermission.
[Behaviors: As described above.]
System.Reflection.PropertyInfo Class, System.Reflection Namespace
public abstract MethodInfo GetSetMethod(bool nonPublic);
Returns the public possibly or, if specified, the non-publicSetaccessor for the property reflected by the current instance.
- nonPublic
- A Boolean value that indicates whether a non-public
Setaccessor will be returned. Specifytrueto allow a non-public accessor; 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 TypeConditionMethodAccessException nonPublic istrue, 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
public MethodInfo GetSetMethod();
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
public abstract object GetValue(object obj, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture);
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 TypeConditionArgumentException index does not contain the exact type of arguments needed.-or-
The
Getaccessor of the property reflected by the current instance was not found.
MethodAccessException TheGetaccessor 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 isnullor 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 virtual object GetValue(object obj, object[] index);
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 TypeConditionArgumentException 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 TheGetaccessor 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 isnullor 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 void SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture);
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 TypeConditionArgumentException The index array does not contain the exact type of arguments needed. TheSetaccessor of the property reflected by the current instance is not found.
TargetException The property reflected by the current instance is non-static, and obj isnullor is of a type that does not implement the property reflected by the current instance.MethodAccessException TheSetaccessor 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
public virtual void SetValue(object obj, object value, object[] index);
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 TypeConditionArgumentException 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 TheSetaccessor 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 isnullor 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