Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
class System.​Reflection.​PropertyInfo
Assembly: System.Runtime
Inheritance: object → MemberInfo → PropertyInfo
Implemented Interfaces
- ICustomAttributeProvider Implemented by: MemberInfo
Discovers the attributes of a property and provides access to property metadata.
Properties
public
PropertyAttributes
Attributes
Gets the attributes for this property.
public
bool
CanRead
Gets a value indicating whether the property can be read.
public
bool
CanWrite
Gets a value indicating whether the property can be written to.
public
MethodInfo
GetMethod
Gets the <see langword="get" /> accessor for this property.
public
bool
IsSpecialName
Gets a value indicating whether the property is the special name.
public
MemberTypes
MemberType
Gets a <see cref="T:System.Reflection.MemberTypes" /> value indicating that this member is a property.
public
Type
PropertyType
Gets the type of this property.
public
MethodInfo
SetMethod
Gets the <see langword="set" /> accessor for this property.
public
Collections.​Generic.​IEnumerable<​CustomAttributeData>
CustomAttributes
Gets a collection that contains this member's custom attributes.
public
Type
DeclaringType
Gets the class that declares this member.
public
bool
IsCollectible
Gets a value that indicates whether this <see cref="T:System.Reflection.MemberInfo" /> object references one or more assemblies held in a collectible <see cref="T:System.Runtime.Loader.AssemblyLoadContext" /> .
public
int
MetadataToken
Gets a value that identifies a metadata element.
public
Module
Module
Gets the module in which the type that declares the member represented by the current <see cref="T:System.Reflection.MemberInfo" /> is defined.
public
string
Name
Gets the name of the current member.
public
Type
ReflectedType
Gets the class object that was used to obtain this instance of <see langword="MemberInfo" /> .
Methods
public
bool
Equals​(object obj)
Returns a value that indicates whether this instance is equal to a specified object.
Returns <see langword="true" /> if <paramref name="obj" /> equals the type and value of this instance; otherwise, <see langword="false" /> .
obj
An object to compare with this instance, or <see langword="null" /> .
public
MethodInfo[]
GetAccessors​()
Returns an array whose elements reflect the public <see langword="get" /> and <see langword="set" /> accessors of the property reflected by the current instance.
Returns An array of <see cref="T:System.Reflection.MethodInfo" /> objects that reflect the public <see langword="get" /> and <see langword="set" /> accessors of the property reflected by the current instance, if found; otherwise, this method returns an array with zero (0) elements.
public
MethodInfo[]
GetAccessors​(bool nonPublic)
Returns an array whose elements reflect the public and, if specified, non-public <see langword="get" /> and <see langword="set" /> accessors of the property reflected by the current instance.
Returns An array whose elements reflect the <see langword="get" /> and <see langword="set" /> accessors of the property reflected by the current instance. If <paramref name="nonPublic" /> is <see langword="true" /> , this array contains public and non-public <see langword="get" /> and <see langword="set" /> accessors. If <paramref name="nonPublic" /> is <see langword="false" /> , this array contains only public <see langword="get" /> and <see langword="set" /> accessors. If no accessors with the specified visibility are found, this method returns an array with zero (0) elements.
nonPublic
Indicates whether non-public methods should be returned in the returned array. <see langword="true" /> if non-public methods are to be included; otherwise, <see langword="false" /> .
public
object
GetConstantValue​()
Returns a literal value associated with the property by a compiler.
Returns An <see cref="T:System.Object" /> that contains the literal value associated with the property. If the literal value is a class type with an element value of zero, the return value is <see langword="null" /> .
public
MethodInfo
GetGetMethod​()
Returns the public <see langword="get" /> accessor for this property.
Returns A <see langword="MethodInfo" /> object representing the public <see langword="get" /> accessor for this property, or <see langword="null" /> if the <see langword="get" /> accessor is non-public or does not exist.
public
MethodInfo
GetGetMethod​(bool nonPublic)
When overridden in a derived class, returns the public or non-public <see langword="get" /> accessor for this property.
Returns A <see langword="MethodInfo" /> object representing the <see langword="get" /> accessor for this property, if <paramref name="nonPublic" /> is <see langword="true" /> . Returns <see langword="null" /> if <paramref name="nonPublic" /> is <see langword="false" /> and the <see langword="get" /> accessor is non-public, or if <paramref name="nonPublic" /> is <see langword="true" /> but no <see langword="get" /> accessors exist.
nonPublic
Indicates whether a non-public <see langword="get" /> accessor should be returned. <see langword="true" /> if a non-public accessor is to be returned; otherwise, <see langword="false" /> .
public
int
GetHashCode​()
Returns the hash code for this instance.
Returns A 32-bit signed integer hash code.
public
ParameterInfo[]
GetIndexParameters​()
When overridden in a derived class, returns an array of all the index parameters for the property.
Returns An array of type <see langword="ParameterInfo" /> containing the parameters for the indexes. If the property is not indexed, the array has 0 (zero) elements.
public
Type
GetModifiedPropertyType​()
Gets the modified type of this property object.
Returns A modified type.
public
Type[]
GetOptionalCustomModifiers​()
Returns an array of types representing the optional custom modifiers of the property.
Returns An array of <see cref="T:System.Type" /> objects that identify the optional custom modifiers of the current property, such as <see cref="T:System.Runtime.CompilerServices.IsConst" /> or <see cref="T:System.Runtime.CompilerServices.IsImplicitlyDereferenced" /> .
public
object
GetRawConstantValue​()
Returns a literal value associated with the property by a compiler.
Returns An <see cref="T:System.Object" /> that contains the literal value associated with the property. If the literal value is a class type with an element value of zero, the return value is <see langword="null" /> .
public
Type[]
GetRequiredCustomModifiers​()
Returns an array of types representing the required custom modifiers of the property.
Returns An array of <see cref="T:System.Type" /> objects that identify the required custom modifiers of the current property, such as <see cref="T:System.Runtime.CompilerServices.IsConst" /> or <see cref="T:System.Runtime.CompilerServices.IsImplicitlyDereferenced" /> .
public
MethodInfo
GetSetMethod​()
Returns the public <see langword="set" /> accessor for this property.
Returns The <see langword="MethodInfo" /> object representing the <see langword="Set" /> method for this property if the <see langword="set" /> accessor is public, or <see langword="null" /> if the <see langword="set" /> accessor is not public.
public
MethodInfo
GetSetMethod​(bool nonPublic)
When overridden in a derived class, returns the <see langword="set" /> accessor for this property.
Returns This property's <see langword="Set" /> method, or <see langword="null" /> , as shown in the following table.
<list type="table">
<listheader>
<term> Value</term>
<description> Condition</description>
</listheader>
<item>
<term> The <see langword="Set" /> method for this property.</term>
<description> The <see langword="set" /> accessor is public, OR <paramref name="nonPublic" /> is <see langword="true" /> and the <see langword="set" /> accessor is non-public.</description>
</item>
<item>
<term>
<see langword="null" />
</term>
<description>
<paramref name="nonPublic" /> is <see langword="true" />, but the property is read-only, OR <paramref name="nonPublic" /> is <see langword="false" /> and the <see langword="set" /> accessor is non-public, OR there is no <see langword="set" /> accessor.</description>
</item>
</list>
nonPublic
Indicates whether the accessor should be returned if it is non-public. <see langword="true" /> if a non-public accessor is to be returned; otherwise, <see langword="false" /> .
public
object
GetValue​(object obj)
Returns the property value of a specified object.
Returns The property value of the specified object.
obj
The object whose property value will be returned.
public
object
GetValue​(object obj,
object[] index)
Returns the property value of a specified object with optional index values for indexed properties.
Returns The property value of the specified object.
obj
The object whose property value will be returned.
index
Optional index values for indexed properties. The indexes of indexed properties are zero-based. This value should be <see langword="null" /> for non-indexed properties.
public
object
GetValue​(object obj,
BindingFlags invokeAttr,
Binder binder,
object[] index,
Globalization.​CultureInfo culture)
When overridden in a derived class, returns the property value of a specified object that has the specified binding, index, and culture-specific information.
Returns The property value of the specified object.
obj
The object whose property value will be returned.
invokeAttr
A bitwise combination of the following enumeration members that specify the invocation attribute: <see langword="InvokeMethod" /> , <see langword="CreateInstance" /> , <see langword="Static" /> , <see langword="GetField" /> , <see langword="SetField" /> , <see langword="GetProperty" /> , and <see langword="SetProperty" /> . You must specify a suitable invocation attribute. For example, to invoke a static member, set the <see langword="Static" /> flag.
binder
An object that enables the binding, coercion of argument types, invocation of members, and retrieval of <see cref="T:System.Reflection.MemberInfo" /> objects through reflection. If <paramref name="binder" /> is <see langword="null" /> , the default binder is used.
index
Optional index values for indexed properties. This value should be <see langword="null" /> for non-indexed properties.
culture
The culture for which the resource is to be localized. If the resource is not localized for this culture, the <see cref="P:System.Globalization.CultureInfo.Parent" /> property will be called successively in search of a match. If this value is <see langword="null" /> , the culture-specific information is obtained from the <see cref="P:System.Globalization.CultureInfo.CurrentUICulture" /> property.
public
void
SetValue​(object obj,
object value)
Sets the property value of a specified object.
obj
The object whose property value will be set.
value
The new property value.
public
void
SetValue​(object obj,
object value,
object[] index)
Sets the property value of a specified object with optional index values for index properties.
obj
The object whose property value will be set.
value
The new property value.
index
Optional index values for indexed properties. This value should be <see langword="null" /> for non-indexed properties.
public
void
SetValue​(object obj,
object value,
BindingFlags invokeAttr,
Binder binder,
object[] index,
Globalization.​CultureInfo culture)
When overridden in a derived class, sets the property value for a specified object that has the specified binding, index, and culture-specific information.
obj
The object whose property value will be set.
value
The new property value.
invokeAttr
A bitwise combination of the following enumeration members that specify the invocation attribute: <see langword="InvokeMethod" /> , <see langword="CreateInstance" /> , <see langword="Static" /> , <see langword="GetField" /> , <see langword="SetField" /> , <see langword="GetProperty" /> , or <see langword="SetProperty" /> . You must specify a suitable invocation attribute. For example, to invoke a static member, set the <see langword="Static" /> flag.
binder
An object that enables the binding, coercion of argument types, invocation of members, and retrieval of <see cref="T:System.Reflection.MemberInfo" /> objects through reflection. If <paramref name="binder" /> is <see langword="null" /> , the default binder is used.
index
Optional index values for indexed properties. This value should be <see langword="null" /> for non-indexed properties.
culture
The culture for which the resource is to be localized. If the resource is not localized for this culture, the <see cref="P:System.Globalization.CultureInfo.Parent" /> property will be called successively in search of a match. If this value is <see langword="null" /> , the culture-specific information is obtained from the <see cref="P:System.Globalization.CultureInfo.CurrentUICulture" /> property.
public
object[]
GetCustomAttributes​(bool inherit)
Inherited from MemberInfo
When overridden in a derived class, returns an array of all custom attributes applied to this member.
Returns An array that contains all the custom attributes applied to this member, or an array with zero elements if no attributes are defined.
inherit
<see langword="true" /> to search this member's inheritance chain to find the attributes; otherwise, <see langword="false" /> . This parameter is ignored for properties and events.
public
object[]
GetCustomAttributes​(Type attributeType,
bool inherit)
Inherited from MemberInfo
When overridden in a derived class, returns an array of custom attributes applied to this member and identified by <see cref="T:System.Type" /> .
Returns An array of custom attributes applied to this member, or an array with zero elements if no attributes assignable to <paramref name="attributeType" /> have been applied.
attributeType
The type of attribute to search for. Only attributes that are assignable to this type are returned.
inherit
<see langword="true" /> to search this member's inheritance chain to find the attributes; otherwise, <see langword="false" /> . This parameter is ignored for properties and events.
public
Collections.​Generic.​IList<​CustomAttributeData>
GetCustomAttributesData​()
Inherited from MemberInfo
Returns a list of <see cref="T:System.Reflection.CustomAttributeData" /> objects representing data about the attributes that have been applied to the target member.
Returns A generic list of <see cref="T:System.Reflection.CustomAttributeData" /> objects representing data about the attributes that have been applied to the target member.
public
bool
IsDefined​(Type attributeType,
bool inherit)
Inherited from MemberInfo
When overridden in a derived class, indicates whether one or more attributes of the specified type or of its derived types is applied to this member.
Returns <see langword="true" /> if one or more instances of <paramref name="attributeType" /> or any of its derived types is applied to this member; otherwise, <see langword="false" /> .
attributeType
The type of custom attribute to search for. The search includes derived types.
inherit
<see langword="true" /> to search this member's inheritance chain to find the attributes; otherwise, <see langword="false" /> . This parameter is ignored for properties and events.
protected
void
Finalize​()
Inherited from object
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
public
Type
GetType​()
Inherited from object
Gets the <see cref="T:System.Type" /> of the current instance.
Returns The exact runtime type of the current instance.
protected
object
MemberwiseClone​()
Inherited from object
Creates a shallow copy of the current <see cref="T:System.Object" /> .
Returns A shallow copy of the current <see cref="T:System.Object" /> .
public
string
ToString​()
Inherited from object
Returns a string that represents the current object.
Returns A string that represents the current object.