I have posted a complete example of this here (see also the post on " this " under it)
Please note that it deals with LambdaExpression , etc. As an update to the code published, you can add a little more to make it easier to use in some scenarios:
static class MemberUtil<TType> { public static string MemberName<TResult>(Expression<Func<TType, TResult>> member) { return MemberUtil.MemberName<TType, TResult>(member); } }
Then you can use generic output type for the return value:
string test1 = MemberUtil<Foo>.MemberName(x => x.Bar); string test2 = MemberUtil<Foo>.MemberName(x => x.Bloop());
source share