ReflectorSetProperty(Type, String, Object, ReflectionWays) Method

Sets the static property of a Type represented by the specified propertyName.

Definition

Namespace: KGySoft.Reflection
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 10.0.0
C#
public static void SetProperty(
	Type type,
	string propertyName,
	Object? value,
	ReflectionWays way = ReflectionWays.Auto
)

Parameters

type  Type
The Type the static property belongs to.
propertyName  String
The name of the property to be set.
value  Object
The value to set.
way  ReflectionWays  (Optional)
The preferred reflection way. TypeDescriptor way is not applicable for static properties. This parameter is optional.
Default value: Auto.

Remarks

propertyName can refer public and non-public properties.

If you already have a PropertyInfo instance use the SetProperty(Object, PropertyInfo, Object, ReflectionWays, Object) method for better performance.

If you are not sure whether a property with the specified propertyName exists, then you can use the TrySetProperty methods instead.

If way is Auto, then this method uses the DynamicDelegate reflection way.

See Also