Last active
July 27, 2018 19:48
-
-
Save rschiefer/a5d6cd715f6978af8c34885b05e0fb9a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 GetName<T>(this Expression<Func<T>> action) | |
{ | |
return GetNameFromMemberExpression(action.Body); | |
} | |
static string GetNameFromMemberExpression(Expression expression) { | |
if (expression is MemberExpression) { | |
return (expression as MemberExpression).Member.Name; | |
} | |
else if (expression is UnaryExpression) { | |
return GetNameFromMemberExpression((expression as UnaryExpression).Operand); | |
} | |
return "MemberNameUnknown"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment