小编Ant*_*ton的帖子

尽管集合中的所有值都为false,但Linq Any返回true

我在属性值计算中看到了非常奇怪的行为.我有一个属性HasChanged,如果它的任何依赖属性为true,则为true.但是我得到了一个结果 - 所有参数都是错误的,结果都是正确的.我正在使用MVVM Light框架,每个属性都是INotifyPropertyChanged

这是辅助函数

    private static bool PropertyWrapper(bool value, [CallerMemberName] string callerName = "")
    {
        Logger.Debug($"[{callerName}: {value}]");
        return value;
    }

    private static T PropertyWrapper<T>(Expression<Func<T>> property)
    {
        var compiled = property.Compile();
        var result = (T)compiled.DynamicInvoke();
        Logger.Debug($"[{GetName(property)}: {result}]");
        return result;
    }

    private static string GetName<T>(Expression<Func<T>> expr)
    {
        var mexpr = expr.Body as MemberExpression;
        if (mexpr == null) return "(null)";
        if (mexpr.Member == null) return "((null))";
        return mexpr.Member.Name;
    }
Run Code Online (Sandbox Code Playgroud)

这是代码

    public virtual bool HasChanged => PropertyWrapper(new[] {
        PropertyWrapper(() => TitleChanged),
        PropertyWrapper(() => …
Run Code Online (Sandbox Code Playgroud)

c# linq any

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

标签 统计

any ×1

c# ×1

linq ×1