简体   繁体   中英

VB2010: Viewing Object Structure for Learning/Visualization Purposes

I was wondering if there is a way to take an object in Visual Basic 2010 (Express, FWIW) and browse through its structure to visualize how the data inside is laid out.

For example, I have an object called "model" that is populated by a function that is a black box to me. Model is set by a "read" function that loads a DXF file from disk. The read function isn't very well-documented.

What I've discovered is that model.Entities ends up containing a list of different objects, all with different properties. I'd like to be able to simply browse this list of objects and view their associated properties and values at run-time, similar to how you can use Intellisense to view a list simply by typing "blah." and waiting for the pop-up to appear.

A tree view that you can pop open and closed would be excellent. Obviously this has to work during run-time rather than in the editor because the file hasn't been loaded if the program isn't running.

Is this something that's possible in Visual Basic 2010? Is it a built-in feature I can't find?

Thanks!

If a function returns an object, then that object has a class definition somewhere. Right-click the reference in VS and select "View in Object Browser" and you'll see the class layout with all properties and methods. You don't need to do this at run-time, either.

If you want to dig even deeper then you should check out Reflector .

EDIT

After reading your comments more, I usually do one of three things when I'm trying to do this:

  1. Use the Autos and Locals window
  2. Use the Immediate Window
  3. Use "break-point and hover"

Use the Autos and Locals window

Set a breakpoint and check out the Autos and Locals windows. If you don't see them they're under the main menu at Debug, Windows. This allows you to walk a tree-view of your variables. Sometimes there can be a lot of stuff in here which I why I generally use one of the other two methods below.

Use the Immediate Window

The Immediate Window (IW) allows you to type in expressions and print out values. Its not a tree-view like you want but it allows you to hunt and peck at least. If you imagine the following short and simple code and you put a breakpoint on the second line:

Dim Names As New List(Of String)({"Alice", "Bob", "Chuck"})
Console.WriteLine(Names)

In the IW you could type:

?Names

And it would output:

Count = 3
    (0): "Alice"
    (1): "Bob"
    (2): "Chuck"

The question mark symbol means "print". You can type almost any valid expression for print:

?Names(0)
"Alice"
?Names(0).Substring(0,1)
"A"
?Names(0).Contains("ice")
True

And as you're doing all of this you're getting IntelliSense about whatever is going on.

Use "break-point and hover"

I don't think this has a name beyond IntelliSense but once you've hit a breakpoint you can hover over any variable and inspect its current values. You'll get the occasionally warning that inspection will cause some processing but since you're debugging only this should be fine. Sometimes when I'm debugging a collection I'll create a variable specific to one item in the collection just to make this technique easier. I'll get rid of it once I'm done debugging but it really helps this process.

Is there another

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM