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 .
public static bool TrySetProperty(
Object instance,
string propertyName,
Object? value,
ReflectionWays way,
params Object?[]? indexParameters
)
Public Shared Function TrySetProperty (
instance As Object,
propertyName As String,
value As Object,
way As ReflectionWays,
ParamArray indexParameters As Object()
) As Boolean
public:
static bool TrySetProperty(
Object^ instance,
String^ propertyName,
Object^ value,
ReflectionWays way,
... array<Object^>^ indexParameters
)
static member TrySetProperty :
instance : Object *
propertyName : string *
value : Object *
way : ReflectionWays *
indexParameters : Object[] -> bool
propertyName can refer public and non-public properties. To avoid ambiguity (in case of indexers), this method gets all of the properties of the same name and chooses the first one for which the provided indexParameters match.
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 TypeDescriptor way for ICustomTypeDescriptor implementations and the DynamicDelegate way otherwise. If the .NET Standard 2.0 version of the KGySoft.CoreLibraries assembly is referenced and the property belongs to a value type (struct), then the SystemReflection way will be used.