Created
May 30, 2016 19:34
-
-
Save ElemarJR/7353e95745cd6da3c09e5cebb633737b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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