ExpressionHelperGetPropertyInfoTOwner, TProperty Method |
Namespace: Lawo.Linq.Expressions
public static PropertyInfo GetPropertyInfo<TOwner, TProperty>( Expression<Func<TOwner, TProperty>> getPropertyExpression )
Exception | Condition |
---|---|
ArgumentNullException | getPropertyExpression equals null. |
ArgumentException | The expression passed for getPropertyExpression does not return the value of a property. |
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.