开发者

Get expression parameter name

I need to get the name of a expression parameter. What i want to do is similar to what FluentNhibernate does with column mapping:

Map(x => x.Name)

From this, i need "Name".

How do I do this?

I can get x by doing this:

Expression<Func<User, object>> exp = x => x.Id;
exp.Parameters[0].Name;

But im not able to get "Name". Note that I dont have any i开发者_如何学Gonstance of T i can invoke on. Thanks


(expr.Body as MemberExpression).Member.Name

As the expression returns object, the body will be wrapped in a Convert expression.

The following should work.

((expr.Body as UnaryExpression).Operand as MemberExpression).Member.Name
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜