Func func = a => a.Id;
I want to get Id from func. Not the value of Id.
func.invoke() give me the value of Id.
As Per suggested comment i tried this. But i got member as null in GetMemberInfo method. I want this approach. ie. i want store func in dictionary. then get that func from dictionary and get the name of Id .
public static MemberInfo GetMemberInfo<T, U>(Expression<Func<T, U>> expression)
{
var member = expression.Body as MemberExpression;
if (member != null)
return member.Member;
throw new ArgumentException("Expression is not a member access", "expression");
}
static void Main(string[] args)
{
Dictionary<int, Func<Soure.Employee, int>> testDir = new Dictionary<int, Func<Soure.Employee, int>>();
testDir.Add(1, p => p.Id);
var testDirValue = testDir[1];
Expression<Func<Soure.Employee, int>> expr1 = mc => testDirValue(mc);
MemberInfo member = Program.GetMemberInfo(expr1);
Console.WriteLine(member.Name);
}