使用INotifyPropertyChanged时指定属性名称的最佳方法是什么?
大多数示例将属性名称硬编码为PropertyChanged事件的参数.我在考虑使用MethodBase.GetCurrentMethod.Name.Substring(4),但对反射开销有点不安.
我有一点问题,我会试着详细解释一下.
在我的系统上,我有一个使用EF 4.1的通用存储库.一切都很棒,但我在某种情况下遇到问题我需要通过一些查询来做动态排序.
我通过参数接收一个表示我班级字段的"字符串"来执行orderBy(如"id"或"description")
部分代码:
public class SomeClass
{
public int id { get; set; }
public string description { get; set; }
}
// First we define the parameter that we are going to use
// in our OrderBy clause. This is the same as "(parameter =>"
// in the example above.
var param = Expression.Parameter(typeof(SomeClass), "parameter");
// Now we'll make our lambda function that returns the
// request.SortingName property by it's name.
var expression = Expression.Lambda<Func<SomeClass, int>>(Expression.Property(param, request.SortingName), …Run Code Online (Sandbox Code Playgroud)