相关疑难解决方法(0)

INotifyPropertyChanged属性名称 - 硬编码与反射?

使用INotifyPropertyChanged时指定属性名称的最佳方法是什么?

大多数示例将属性名称硬编码为PropertyChanged事件的参数.我在考虑使用MethodBase.GetCurrentMethod.Name.Substring(4),但对反射开销有点不安.

.net reflection wpf

41
推荐指数
6
解决办法
2万
查看次数

LINQ - OrderBy的动态表达式

我有一点问题,我会试着详细解释一下.

在我的系统上,我有一个使用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)

linq asp.net-mvc entity-framework

2
推荐指数
1
解决办法
5527
查看次数

标签 统计

.net ×1

asp.net-mvc ×1

entity-framework ×1

linq ×1

reflection ×1

wpf ×1