PropertyAccessorSet(Object, Object, Object) Method

Sets the property. For static properties the instance parameter is omitted (can be ). If the property is not an indexer, then indexParameters parameter is omitted.

Definition

Namespace: KGySoft.Reflection
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 9.0.0
C#
public void Set(
	Object? instance,
	Object? value,
	params Object?[]? indexParameters
)

Parameters

instance  Object
The instance that the property belongs to. Can be for static properties.
value  Object
The value to set.
indexParameters  Object
The parameters if the property is an indexer.

Remarks

Setting the property for the first time is slower than the System.Reflection.PropertyInfo.SetValue method but further calls are much faster.

The method can be use also for ref properties.

  Tip

If the property has no more than one index parameters and you know the type of the property at compile time (and also the declaring type for instance properties), then you can use the generic SetStaticValue or SetInstanceValue methods for better performance.

  Notes to Callers

If the property is an instance property of a value type, then the .NET Standard 2.0 version of this method defaults to use regular reflection to preserve mutations. To experience the best performance try to target .NET Standard 2.1 or any .NET Framework or .NET Core/.NET platforms instead.

Exceptions

ArgumentNullExceptionThis PropertyAccessor represents an instance property and instance is
-or-
This PropertyAccessor represents a value type property and value is .
-or-
This PropertyAccessor represents an indexed property and indexParameters is .
ArgumentExceptionThe type of instance, value or one of the indexParameters is invalid.
-or-
indexParameters has too few elements.
InvalidOperationExceptionThe PropertyAccessor represents a property of an open generic type.
NotSupportedExceptionThis PropertyAccessor represents a read-only property.
-or-
On .NET Framework the code is executed in a partially trusted domain with insufficient permissions.
PlatformNotSupportedExceptionYou use the .NET Standard 2.0 build of KGySoft.CoreLibraries and this PropertyAccessor represents a ref property.

See Also