PostSharp 2023.0 / / Post­Sharp Documentation / API Reference / Post­Sharp.​Patterns.​Utilities Namespace / Unknown­Object­Accessor Structure / Unknown­Object­Accessor Methods / Unknown­Object­Accessor.​Try­Get­Property Method / Unknown­Object­Accessor.​Try­Get­Property(T) Method (Object, String, T)

UnknownObjectAccessor.TryGetProperty<T> Method (Object, String, T)

Gets the value of a named property for an arbitrary object.

Namespace:  PostSharp.Patterns.Utilities
Assembly:  PostSharp.Patterns.Common (in PostSharp.Patterns.Common.dll) Version: 2023.0.3.0 (2023.0.3.0)
Syntax
C#
public static bool TryGetProperty<T>(
	Object instance,
	string name,
	out T value
)

Parameters

instance
Type: System.Object
The object whose property has to be returned.
name
Type: System.String
Property name.
value
Type: T
Returns the property value if a property named name exists and its value can be cast to T, otherwise default.

Type Parameters

T
Type of the property value.

Return Value

Type: Boolean
true if the property value if a property named name exists and its value can be cast to T, otherwise false.
See Also