PropertyInfo.SetValue Method (Object, Object, BindingFlags, Binder, array<Object>[]()[], CultureInfo)

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

When overridden in a derived class, sets the property value for the given object to the given value, subject to the specified binding constraints, binder, and culture.

Namespace:  System.Reflection
Assembly:  mscorlib (in mscorlib.dll)

Syntax

Public MustOverride Sub SetValue ( _
    obj As Object, _
    value As Object, _
    invokeAttr As BindingFlags, _
    binder As Binder, _
    index As Object(), _
    culture As CultureInfo _
)
public abstract void SetValue(
    Object obj,
    Object value,
    BindingFlags invokeAttr,
    Binder binder,
    Object[] index,
    CultureInfo culture
)

Parameters

  • invokeAttr
    Type: System.Reflection..::.BindingFlags
    The invocation attribute. This must be a bit flag from BindingFlags: InvokeMethod, CreateInstance, Static, GetField, SetField, GetProperty, or SetProperty. A suitable invocation attribute must be specified. If a static member is to be invoked, the Static flag of BindingFlags must be set.
  • binder
    Type: System.Reflection..::.Binder
    An object that enables the binding, coercion of argument types, invocation of members, and retrieval of MemberInfo objects through reflection. If binder is nullNothingnullptra null reference (Nothing in Visual Basic), the default binder is used.
  • index
    Type: array<System..::.Object>[]()[]
    Optional index values for indexed properties. This value should be nullNothingnullptra null reference (Nothing in Visual Basic) for non-indexed properties.
  • culture
    Type: System.Globalization..::.CultureInfo
    The culture for which the resource is to be localized. Note that if the resource is not localized for this culture, the CultureInfo.Parent method will be called successively in search of a match. If this value is nullNothingnullptra null reference (Nothing in Visual Basic), the CultureInfo is obtained from the CultureInfo.CurrentUICulture property.

Exceptions

Exception Condition
ArgumentException

The index array does not contain the type of arguments needed.

-or-

The property's set accessor is not found.

TargetException

The object does not match the target type, or a property is an instance property but obj is nullNothingnullptra null reference (Nothing in Visual Basic).

TargetParameterCountException

The number of parameters in index does not match the number of parameters the indexed property takes.

MethodAccessException

The property is not accessible to the caller.

TargetInvocationException

An error occurred while setting the property value. For example, an index value specified for an indexed property is out of range. The InnerException property indicates the reason for the error.

Remarks

To determine whether a property is indexed, use the GetIndexParameters method. If the resulting array has 0 (zero) elements, the property is not indexed.

In Windows Phone, only accessible properties can be set using reflection.

To use the SetValue method, first get the class Type. From the Type, get the PropertyInfo. From the PropertyInfo, use the SetValue method.

Version Information

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Platforms

Windows Phone

See Also

Reference

PropertyInfo Class

SetValue Overload

System.Reflection Namespace