ReflectorTrySetProperty(Type, String, Object, ReflectionWays) Method

Tries to set 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 bool TrySetProperty(
	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.

Return Value

Boolean
, if the property could be set; , if a matching property could not be found.

Remarks

  Note

If a matching property could be found and the invocation itself has thrown an exception, then this method also throws an exception instead of returning .

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 way is Auto, then this method uses the DynamicDelegate reflection way.

See Also