Skip to content

Instantly share code, notes, and snippets.

@peyangu
Created March 15, 2017 08:02
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 peyangu/92bd0a9d60ac9c56d9b5695de95f5a42 to your computer and use it in GitHub Desktop.
Save peyangu/92bd0a9d60ac9c56d9b5695de95f5a42 to your computer and use it in GitHub Desktop.
プロパティ名の取得
using System.Linq.Expressions;
static class PropertyGet
{
/// <summary>
/// プロパティ名を取得する
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="e"></param>
/// <returns></returns>
public static string GetPropertyName<T>(Expression<Func<T>> e)
{
var memberEx = (MemberExpression)e.Body;
return memberEx.Member.Name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment