ReflectorTryGetProperty(Object, String, Boolean, ReflectionWays, Object, Object) Method

Tries to get the instance property of an object represented by the specified propertyName.

Definition

Namespace: KGySoft.Reflection
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 8.1.0
C#
public static bool TryGetProperty(
	Object instance,
	string propertyName,
	bool ignoreCase,
	ReflectionWays way,
	out Object?? value,
	params Object?[]? indexParameters
)

Parameters

instance  Object
An instance whose property is about to be retrieved.
propertyName  String
The name of the property to get.
ignoreCase  Boolean
to ignore case; to regard case.
way  ReflectionWays
The preferred reflection way.
value  Object
When this method returns with result, then this parameter contains the value of the property.
indexParameters  Object
Index parameters if propertyName refers to an indexed property. This parameter is ignored for non-indexed properties.

Return Value

Boolean
, if the property could be read; , 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. 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 GetProperty(Object, PropertyInfo, 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.

See Also