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 throughGet
andSet
accessors. [Note: Properties can be read-only, in which case theSet
accessor is not available.]
Several methods in this class assume that the
Get
andSet
accessors 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
Get
accessor and the last argument of theSet
accessor are required to be identical to the type of the property reflected by the current instance.- The
Get
andSet
accessors 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
true
to 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-publicGet
accessor for the property reflected by the current instance.
- nonPublic
- A Boolean value that indicates whether a non-public
Get
accessor will be returned. Specifytrue
to allow a non-public accessor; otherwise, specifyfalse
.
If nonPublic istrue
, returns a MethodInfo instance that reflects theGet
accessor for the property reflected by the current instance if that accessor exists. If nonPublic isfalse
and theGet
accessor is non-public, or nonPublic istrue
but noGet
accessor exists for the property reflected by the current instance, returnsnull
.
Exception Type Condition MethodAccessException nonPublic is true
, theGet
accessor 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 publicGet
accessor for the property reflected by the current instance.
A MethodInfo instance that reflects the publicGet
accessor for the property reflected by the current instance. Returnsnull
if no publicGet
accessor 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 Type Condition MethodAccessException The property reflected by the current instance is visible, but its Get
andSet
accessors 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-publicSet
accessor for the property reflected by the current instance.
- nonPublic
- A Boolean value that indicates whether a non-public
Set
accessor will be returned. Specifytrue
to allow a non-public accessor; otherwise, specifyfalse
.
If nonPublic istrue
, returns a MethodInfo instance that reflects theSet
accessor for the property reflected by the current instance if that accessor exists. If nonPublic isfalse
and theSet
accessor is non-public, or nonPublic istrue
but noSet
accessor exists for the property reflected by the current instance, returnsnull
.
Exception Type Condition MethodAccessException nonPublic is true
, theSet
accessor 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 publicSet
accessor for the property reflected by the current instance.
A MethodInfo instance that reflects the publicSet
accessor for the property reflected by the current instance. Returnsnull
if no publicSet
accessor 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
null
to invoke a staticGet
accessor 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
get
accessors 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
null
for 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. -or-
The
Get
accessor of the property reflected by the current instance was not found.
MethodAccessException The Get
accessor 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 null
or 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
null
to invoke a staticGet
accessor of a property.- index
- An array of objects that is an index of values for indexed properties. This value is required to be
null
for 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
Get
accessor of the property reflected by the current instance is not found.
MethodAccessException The Get
accessor 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 null
or 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
null
to invoke a staticSet
accessor 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
Set
accessors 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
null
for 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 Set
accessor 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 null
or is of a type that does not implement the property reflected by the current instance.MethodAccessException The Set
accessor 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
null
to invoke a staticSet
accessor 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
null
for non-indexed properties.
Exception Type Condition ArgumentException index does not contain the exact type of arguments needed. -or-
The
Set
accessor of the property reflected by the current instance was not found.
MethodAccessException The Set
accessor 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 null
or 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 aGet
accessor.
true
if the property reflected by the current instance has aGet
accessor; 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 aSet
accessor.
true
if the property reflected by the current instance has aSet
accessor; 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