Skip to content

Commit

Permalink
Extra reflection helper
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMpn committed Apr 23, 2024
1 parent 456a019 commit ac39dd0
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions MarkMpn.Sql4Cds.Engine/ExpressionFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,23 @@ private static MethodInfo GetMethodInfo(LambdaExpression expression)
return outermostExpression.Method;
}

/// <summary>
/// Given a lambda expression that accesses a property, return the property info
/// </summary>
/// <typeparam name="T">The type of value returned by the property</typeparam>
/// <param name="expression">The expression</param>
/// <returns>The property details</returns>
public static PropertyInfo GetPropertyInfo<T>(Expression<Func<T>> expression)
{
var lambda = (LambdaExpression)expression;
var prop = lambda.Body as MemberExpression;

if (prop == null)
throw new ArgumentException("Invalid Expression. Expression should consist of a property access only.");

return prop.Member as PropertyInfo;
}

/// <summary>
/// Placeholder for a function argument when using <see cref="Call{T}(Expression{Func{T}}, Expression[])"/>
/// </summary>
Expand Down

0 comments on commit ac39dd0

Please sign in to comment.