Skip to content

Instantly share code, notes, and snippets.

@ElemarJR
Created May 30, 2016 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ElemarJR/7353e95745cd6da3c09e5cebb633737b to your computer and use it in GitHub Desktop.
Save ElemarJR/7353e95745cd6da3c09e5cebb633737b to your computer and use it in GitHub Desktop.
public static string ToPropertyPath<TB, T>(this Expression<Func<TB, T>> func)
{
var result = new StringBuilder();
var node = func.Body;
while (node.NodeType == ExpressionType.MemberAccess)
{
var me = node as MemberExpression;
if (result.Length != 0) result.Insert(0, ".");
result.Insert(0, me.Member.Name);
node = me.Expression;
}
return result.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment