When overridden in a derived class, returns the property value of a specified object that has the specified binding, index, and culture-specific information.
- invokeAttr
- A bitwise combination of the following enumeration members that specify the invocation attribute: InvokeMethod, CreateInstance, Static, GetField, SetField, GetProperty, and SetProperty. You must specify a suitable invocation attribute. For example, to invoke a static member, set the Static flag.
- binder
- An object that enables the binding, coercion of argument types, invocation of members, and retrieval of System.Reflection.MemberInfo objects through reflection. If binder is null, the default binder is used.
- index
- Optional index values for indexed properties. This value should be 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 System.Globalization.CultureInfo.Parent property will be called successively in search of a match. If this value is null, the culture-specific information is obtained from the System.Globalization.CultureInfo.CurrentUICulture property.
- obj
- The object whose property value will be returned.
- invokeAttr
- A bitwise combination of the following enumeration members that specify the invocation attribute: InvokeMethod, CreateInstance, Static, GetField, SetField, GetProperty, and SetProperty. You must specify a suitable invocation attribute. For example, to invoke a static member, set the Static flag.
- binder
- An object that enables the binding, coercion of argument types, invocation of members, and retrieval of System.Reflection.MemberInfo objects through reflection. If binder is null, the default binder is used.
- index
- Optional index values for indexed properties. This value should be 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 System.Globalization.CultureInfo.Parent property will be called successively in search of a match. If this value is null, the culture-specific information is obtained from the System.Globalization.CultureInfo.CurrentUICulture property.
The property value of the specified object.
Type Reason 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 System.Security.Permissions.ReflectionPermission to reflect on non-public methods. System.Reflection.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. System.Reflection.TargetParameterCountException The current instance reflects an indexer and index.Length does not equal the rank of the indexer.
To determine whether a property is indexed, use the PropertyInfo.GetIndexParameters method. If the resulting array has 0 (zero) elements, the property is not indexed.
Because static properties belong to the type, not individual objects, get static properties by passing null as the object argument. For example, use the following code to get the static CurrentCulture property of CultureInfo :
Example
PropertyInfo CurCultProp = (typeof(CultureInfo)).GetProperty("CurrentCulture"); Console.WriteLine("CurrCult: " + CurCultProp.GetValue(null,null));
To use the GetValue method, first get the class Type. From the Type, get the PropertyInfo. From the PropertyInfo, use the GetValue method.
Starting with the net_v20sp1_long, this method can be used to access non-public members if the caller has been granted System.Security.Permissions.ReflectionPermission with the System.Security.Permissions.ReflectionPermissionFlag.RestrictedMemberAccess flag and if the grant set of the non-public members is restricted to the caller’s grant set, or a subset thereof. (See Security Considerations for Reflection.)
To use this functionality, your application should target the net_v35_long or later.
Type | Reason |
---|---|
System.Security.Permissions.ReflectionPermission | Requires permission to reflect non-public members of a type in loaded assemblies. See System.Security.Permissions.ReflectionPermissionFlag.MemberAccess. |