Created
March 15, 2017 08:02
-
-
Save peyangu/92bd0a9d60ac9c56d9b5695de95f5a42 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
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