Note that there are some explanatory texts on larger screens.

plurals
  1. POIterate enumerable object while debugging in Visual Studio
    primarykey
    data
    text
    <p>Is it possible to iterate collection and list only filtered object information while debugging in Visual Studio? I'd use Immediate window for that, but although it allows to execute methods on objects, it seems not to allow execute custom loop statements.</p> <p>Simplest example in ASP.NET:</p> <pre><code>this.Page.Validate(); if (!this.Page.IsValid()) { // breakpoint here } </code></pre> <p>How can we iterate <code>Page.Validators</code> collection and find those which are invalid + output their information at that breakpoint? (this is not the main question, it's just a sample)</p> <p>If it's not possible to do it straight forward, do you have any workarounds for this? Workarounds which would not involve code modification, just writing code in Immediate window or some Watch expression.</p> <p>While googling I've found just one workaround quoted <a href="http://visualstudiohacks.com/articles/ask-the-pros/ask-the-pros-debugging/" rel="noreferrer">here</a> (although could not find the original):</p> <blockquote> <p>"Add a debug method to your code that does something like iterate through all the objects in a collection. Then you can call that method from the immediate window while in debug mode and it will enumerate various things for you. Think of it like a command-line-debugger-helper. You can write as many of those as you like."</p> </blockquote> <p>But it's still a workaround. I image it should be doable without too much hacking and more importantly without modifying code. Of course it should be possible to do some kind of collection transformations in one statement.</p> <p>And let's stick to non-generic collections. Also Immediate window seems not to accept lambda expressions (got an error when tried: "Expression cannot contain lambda expressions")</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload