Skip to content

Instantly share code, notes, and snippets.

@Larry57
Last active November 19, 2015 09:57
Show Gist options
  • Save Larry57/37db91489bf7a7244efb to your computer and use it in GitHub Desktop.
Save Larry57/37db91489bf7a7244efb to your computer and use it in GitHub Desktop.
Return the full path of a property name
// Inspired by http://stackoverflow.com/q/301809/24472
public static string Property<TProp>(Expression<Func<T, TProp>> expression)
{
var s = expression.Body.ToString();
var p = s.Remove(0, s.IndexOf('.') + 1);
return p;
}
// Example:
var s = Nameof<DataGridViewCell>.Property(c => c.Style.BackColor.A);
// s: "Style.BackColor.A"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment