Click or drag to resize
ExpressionHelperGetPropertyInfoTOwner, TProperty Method
Returns the PropertyInfo associated with the property identified by getPropertyExpression.

Namespace: Lawo.Linq.Expressions
Assembly: Lawo (in Lawo.dll) Version: 1.4.1707.27006
Syntax
C#
public static PropertyInfo GetPropertyInfo<TOwner, TProperty>(
	Expression<Func<TOwner, TProperty>> getPropertyExpression
)

Parameters

getPropertyExpression
Type: System.Linq.ExpressionsExpressionFuncTOwner, TProperty
An expression calling the getter of a property, for example (Type t) => t.FullName.

Type Parameters

TOwner
The type of the owner of the property.
TProperty
The type of the property.

Return Value

Type: PropertyInfo
Exceptions
ExceptionCondition
ArgumentNullExceptiongetPropertyExpression equals null.
ArgumentExceptionThe expression passed for getPropertyExpression does not return the value of a property.
Remarks

Both TOwner and TProperty are automatically deduced from the expression passed for getPropertyExpression and therefore do not need to be specified explicitly.

This method is helpful whenever code needs to retrieve the PropertyInfo associated with the property of a given type.

It is superior to GetDeclaredProperty(String), because it avoids duplicating the name of the property in a string. Such duplicated names are often forgotten during refactoring and the resulting bugs can only be found during testing. The specified expression is a language element that is checked for consistency at compile time and is automatically changed during refactoring.

See Also