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 is 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.
This is a convenience method that provides an implementation for the abstract GetValue method with a BindingFlags parameter of Default, the Binder set to null, and the CultureInfo set to null.
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. |