Retrieving Property name from lambda expression

前端 未结 21 2034
迷失自我
迷失自我 2020-11-21 11:12

Is there a better way to get the Property name when passed in via a lambda expression? Here is what i currently have.

eg.

GetSortingInfo         


        
21条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-21 11:53

    now in C# 6 you can simply use nameof like this nameof(User.UserId)

    which has many benefits, among them is that this is done at compile time, not runtime.

    https://msdn.microsoft.com/en-us/magazine/dn802602.aspx

提交回复
热议问题