代码之家  ›  专栏  ›  技术社区  ›  Gonzalo.-

条件断点在Visual Studio 2015中不工作

  •  6
  • Gonzalo.-  · 技术社区  · 8 年前

    所以我补充说 hierarchyRelation != null 作为条件。这是我正在调试的方法的局部变量,它是存在的。

    “断点的条件未能执行。该条件为 条件必须计算为布尔运算”。单击“确定”停止 此断点。

    实际上,条件更复杂,但这是再现问题的最简单情况。我尝试了变量,甚至比较了这个变量的属性,但它总是失败。

    如果我尝试一个恒定条件,比如 1 != 2 1 = 1 它工作得很好。有什么问题吗?我发现的最相关的问题是 this vb code . 它的解决方案是直接在代码中添加调试方法。虽然我能做到,但我想知道为什么这不起作用。

    private HierarchyNodeDto GetNodeTreeThatContainsText<TRollup, TLeaf, THierarchyRelation>(HierarchyNodeDto root, string text, PreFilter preFilter, Func<TLeaf, bool> leafContainsTextFunc, bool parentContainsText) where TRollup: HierarchyNodeDto where TLeaf: HierarchyNodeDto {
                dynamic rootNode = root as TRollup;
                if (rootNode != null) {
                    if (rootNode.Nodes == null) {
                        return null;
                    }
                    var childNodesWithText = new List<THierarchyRelation>();
                    foreach (var hierarchyRelation in rootNode.Nodes) {
                        var isLeaf = hierarchyRelation.Node.GetType() == typeof(TransactionTypeHierarchyLeafDto) || hierarchyRelation.Node.GetType() == typeof(AccountHierarchyLeafDto);
                        if (!isLeaf && hierarchyRelation.Node.Name != null && hierarchyRelation.Node.Name.ToLower().Contains(text) && preFilter != PreFilter.Leafs) {
                            childNodesWithText.Add(hierarchyRelation);
                            continue;
                        }
                        var subtreeThatContainsText = this.GetNodeTreeThatContainsText<TRollup, TLeaf, THierarchyRelation>(hierarchyRelation.Node, text, preFilter, leafContainsTextFunc, rootNode.Name.ToLower().Contains(text));
                        if (subtreeThatContainsText == null) {
                            continue;
                        }
                        hierarchyRelation.Node = subtreeThatContainsText;
                        childNodesWithText.Add(hierarchyRelation);
                    }
                    rootNode.Nodes = childNodesWithText;
                    if (rootNode.Nodes.Count > 0 || (rootNode.Name.ToLower().Contains(text) && preFilter != PreFilter.Leafs)) {
                        return rootNode;
                    }
                    return null;
                }
                var rootLeaf = root as TLeaf;
    
                return rootLeaf != null && ((leafContainsTextFunc.Invoke(rootLeaf) && preFilter != PreFilter.Nodes) || (parentContainsText && preFilter != PreFilter.Leafs)) ? rootLeaf : null;
            }
    

    我在 foreach

    enter image description here

    2 回复  |  直到 8 年前
        1
  •  6
  •   kileak    8 年前

    (object)hierarchyRelation!=null
    

    试一试,看看这是否适合你。

        2
  •  5
  •   Jevgeni Geurtsen    8 年前

    问题是 hierarchyRelation Expressions in the Debugger 它应该会起作用(我找不到不起作用的原因)。

        static void Main(string[] args)
        {
            dynamic foo = new Foo();
    
            // conditional breakpoint 'foo.Nodes == null' here
        }
    
        internal class Foo
        {
            public IEnumerable<Foo> Nodes = null;
        }
    

    foo 变量将使调试器能够计算表达式并在需要时中断。