System.Reflection.PropertyInfo Class

public abstract class PropertyInfo : MemberInfo

Base Types

Object
  MemberInfo
    PropertyInfo

Assembly

mscorlib

Library

Reflection

Summary

Provides access to property metadata.

Description

A property is a named aspect of an object's state whose value is typically accessible through get and set accessors. [Note: Properties can be read-only, in which case the set accessor is not available.]

Several methods in this class assume that the Get and Set 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.

See Also

System.Reflection Namespace

Members

PropertyInfo Constructors

PropertyInfo Constructor

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


PropertyInfo Constructor

protected PropertyInfo();

Summary

Constructs a new instance of the PropertyInfo class.

See Also

System.Reflection.PropertyInfo Class, System.Reflection Namespace

PropertyInfo.GetAccessors(bool) Method

public abstract MethodInfo[] GetAccessors(bool nonPublic);

Summary

Returns an array whose elements reflect the public and, if specified, non-public Get , Set , and other accessors of the property reflected by the current instance.

Parameters

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, specify false .

Return Value

An array of MethodInfo objects whose elements reflect the Get , Set , and other accessors of the property reflected by the current instance. If nonPublic is true , this array contains public and non-public accessors. If nonPublic is false , this array contains only public accessors. If no accessors with the specified visibility are found, returns an array with zero elements.

Description

[Behaviors: As described above.]

See Also

System.Reflection.PropertyInfo Class, System.Reflection Namespace

PropertyInfo.GetAccessors() Method

public MethodInfo[] GetAccessors();

Summary

Returns an array whose elements reflect the public Get , Set , and other accessors of the property reflected by the current instance.

Return Value

An array of MethodInfo objects that reflect the public Get , Set , and other accessors of the property reflected by the current instance, if found; otherwise, returns an array with zero elements.

Description

This method is equivalent to System.Reflection.PropertyInfo.GetAccessors(false ).

See Also

System.Reflection.PropertyInfo Class, System.Reflection Namespace

PropertyInfo.GetGetMethod(bool) Method

public abstract MethodInfo GetGetMethod(bool nonPublic);

Summary

Returns the public or, if specified, non-public Get accessor for the property reflected by the current instance.

Parameters

nonPublic
A Boolean value that indicates whether non-public Get accessors will be included in the return value. Specify true to include non-public accessors; otherwise, specify false .

Return Value

If nonPublic is true , returns a MethodInfo instance that reflects the Get accessor for the property reflected by the current instance if that accessor exists. If nonPublic is false and the Get accessor is non-public, or nonPublic is true but no Get accessor exists for the property reflected by the current instance, returns null .

Exceptions

Exception TypeCondition
MethodAccessExceptionnonPublic is true , the Get 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.

Description

[Behaviors: As described above.]

See Also

System.Reflection.PropertyInfo Class, System.Reflection Namespace

PropertyInfo.GetGetMethod() Method

public MethodInfo GetGetMethod();

Summary

Returns the public Get accessor for the property reflected by the current instance.

Return Value

A MethodInfo instance that reflects the public Get accessor for the property reflected by the current instance. Returns null if no public Get accessor exists.

See Also

System.Reflection.PropertyInfo Class, System.Reflection Namespace

PropertyInfo.GetIndexParameters Method

public abstract ParameterInfo[] GetIndexParameters();

Summary

Returns an array of the indexers of the property reflected by the current instance.

Return Value

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.

Exceptions

Exception TypeCondition
MethodAccessExceptionThe property reflected by the current instance is visible, but its Get and Set accessors are not, and the caller does not have ReflectionPermission.

Description

[Behaviors: As described above.]

See Also

System.Reflection.PropertyInfo Class, System.Reflection Namespace

PropertyInfo.GetSetMethod(bool) Method

public abstract MethodInfo GetSetMethod(bool nonPublic);

Summary

Returns the public or, if specified, non-public Set accessor for the property reflected by the current instance.

Parameters

nonPublic
A Boolean value that indicates whether non-public Set accessors are included in the return value. Specify true if non-public accessors are to be included; otherwise, specify false .

Return Value

If nonPublic is true , returns a MethodInfo instance that reflects the Set accessor for the property reflected by the current instance if that accessor exists. If nonPublic is false and the Set accessor is non-public, or nonPublic is true but no Set accessor exists for the property reflected by the current instance, returns null .

Exceptions

Exception TypeCondition
MethodAccessExceptionnonPublic is true , the Set 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.

Description

[Behaviors: As described above.]

See Also

System.Reflection.PropertyInfo Class, System.Reflection Namespace

PropertyInfo.GetSetMethod() Method

public MethodInfo GetSetMethod();

Summary

Returns the public Set accessor for the property reflected by the current instance.

Return Value

A MethodInfo instance that reflects the public Set accessor for the property reflected by the current instance. Returns null if no public Set accessor exists.

Description

This method is equivalent to System.Reflection.PropertyInfo.GetSetMethod(false ).

See Also

System.Reflection.PropertyInfo Class, System.Reflection Namespace

PropertyInfo.GetValue(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo) Method

public abstract object GetValue(object obj, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture);

Summary

Returns the value of the property that is reflected by the current instance in the specified object and corresponds to the specified criteria.

Parameters

obj
The object whose property value is returned. Specify null to invoke a static Get 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 .

Return Value

A Object that contains the property value for obj .

Exceptions

Exception TypeCondition
ArgumentExceptionindex does not contain the exact type of arguments needed.

The Get accessor of the property reflected by the current instance was not found.

MethodAccessExceptionThe 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.
TargetExceptionThe 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.
TargetParameterCountExceptionThe current instance reflects an indexer and index.Length does not equal the rank of the indexer.

Description

[Behaviors: As described above.]

See Also

System.Reflection.PropertyInfo Class, System.Reflection Namespace

PropertyInfo.GetValue(System.Object, System.Object[]) Method

public virtual object GetValue(object obj, object[] index);

Summary

Returns the value of the property reflected by the current instance in the specified object, using the specified index values.

Parameters

obj
The object whose property value will be returned. Specify null to invoke a static Get 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.

Return Value

A Object that contains the property value for obj .

Exceptions

Exception TypeCondition
ArgumentExceptionindex does not contain the exact type of arguments needed.

-or-

The Get accessor of the property reflected by the current instance is not found.

MethodAccessExceptionThe 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.
TargetExceptionThe 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.
TargetParameterCountExceptionThe current instance reflects an indexer and index.Length does not equal the rank of the indexer.

Description

[Behaviors: As described above.]

See Also

System.Reflection.PropertyInfo Class, System.Reflection Namespace

PropertyInfo.SetValue(System.Object, System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo) Method

public abstract void SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture);

Summary

Sets the value of the property that is reflected by the current instance on the specified objects and corresponds to the specified properties.

Parameters

obj
The object whose property value is returned. Specify null to invoke a static Set 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 .

Exceptions

Exception TypeCondition
ArgumentExceptionThe 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.

TargetExceptionThe 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.
MethodAccessExceptionThe 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.
TargetParameterCountExceptionThe current instance reflects an indexer and index.Length does not equal the rank of the indexer.

Description

[Behaviors: As described above.]

See Also

System.Reflection.PropertyInfo Class, System.Reflection Namespace

PropertyInfo.SetValue(System.Object, System.Object, System.Object[]) Method

public virtual void SetValue(object obj, object value, object[] index);

Summary

Sets the value of the property reflected by the current instance on the specified object, using the specified index values.

Parameters

obj
The object whose property value is returned. Specify null to invoke a static Set 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.

Exceptions

Exception TypeCondition
ArgumentExceptionindex does not contain the exact type of arguments needed.

-or-

The Set accessor of the property reflected by the current instance was not found.

MethodAccessExceptionThe 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.
TargetExceptionThe 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.
TargetParameterCountExceptionThe current instance reflects an indexer and index.Length does not equal the rank of the indexer.

Description

[Behaviors: As described above.]

See Also

System.Reflection.PropertyInfo Class, System.Reflection Namespace

PropertyInfo.Attributes Property

public abstract PropertyAttributes Attributes { get; }

Summary

Gets the attributes of the property reflected by the current instance.

Property Value

A PropertyAttributes value that specifies the attributes of the property reflected by the current instance.

Description

[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.]

See Also

System.Reflection.PropertyInfo Class, System.Reflection Namespace

PropertyInfo.CanRead Property

public abstract bool CanRead { get; }

Summary

Gets a Boolean value indicating whether the property reflected by the current instance has a Get accessor.

Property Value

true if the property reflected by the current instance has a Get accessor; otherwise, false .

Description

[Behaviors: This property is read-only.]

See Also

System.Reflection.PropertyInfo Class, System.Reflection Namespace

PropertyInfo.CanWrite Property

public abstract bool CanWrite { get; }

Summary

Gets a Boolean value indicating whether the property reflected by the current instance has a Set accessor.

Property Value

true if the property reflected by the current instance has a Set accessor; otherwise, false .

Description

[Behaviors: This property is read-only.]

See Also

System.Reflection.PropertyInfo Class, System.Reflection Namespace

PropertyInfo.PropertyType Property

public abstract Type PropertyType { get; }

Summary

Gets the type of the property reflected by the current instance.

Property Value

A Type that represents the type of the property reflected by the current instance.

Description

[Behaviors: This property is read-only.]

See Also

System.Reflection.PropertyInfo Class, System.Reflection Namespace