ReflectorTryGetProperty(Type, String, Object, ReflectionWays) Method

Tries to get 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 TryGetProperty(
	Type type,
	string propertyName,
	out Object?? value,
	ReflectionWays way = ReflectionWays.Auto
)

Parameters

type  Type
The Type the static property belongs to.
propertyName  String
The name of the property to get.
value  Object
When this method returns with result, then this parameter contains the value of the property.
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 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.

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 DynamicDelegate reflection way.

See Also