Visual Studio Immediate window: how to see more than the first 100 items - visual-studio

I am trying to see the properties of an object with over 300 properties in the Immediate Window of Visual Studio 2005. Only the first 100 items are displayed, followed by this caption:
< More... (The first 100 of 306 items were displayed.) >
I am trying to see the rest of the items, but can't figure it out.
I realize that I could see these in a Watch window, but that's not the same.

Sometimes its useful to see the list in the immediate window rather than looking in the watch window. You can easily see more results than the first 100 by using:
yourList.Skip(100).ToArray()
Which really doesn't take long to write and works well - was useful for me.
Update: As pointed out in the comments below, this answer is actually wrong and applicable ONLY to collections and NOT to objects with lots of properties. I'm leaving it here as lots of people seem to have found it useful.

If you add your object to the watch window, then expand the properties so that all are displayed. Then Ctrl+A and Copy. You can then paste in excel to get an organized list of properties and their values.

The immediate window was designed to be a quick view tool. If you want to see more detail, you will have to view it in either the Watch Window or the Quick Watch Window.
Another option is to write a Visual Studio AddIn that operates similarly to the Immediate Window, but has more options.

I always create an extension method to export objects to xml when debugging like this. It's very useful for troubleshooting object data. Here is what I use:
public static void SerializeToXML(this object entity)
{
System.Xml.Serialization.XmlSerializer writer = new System.Xml.Serialization.XmlSerializer(entity.GetType());
System.IO.StreamWriter file = new System.IO.StreamWriter(string.Format(#"{0}\{1}.xml", Directory.GetCurrentDirectory(), entity.GetType().Name));
writer.Serialize(file, entity);
file.Close();
}
It's not 100% full proof, but most of the time it is perfect. It will create an xml file in the application directory with the objects name as the file name. In the immediate window you can just type the object name then .SerializeToXML().
so: myList.SerializeToXML()

Its an old question but to get the properties and values of an object during runtime a more reasonable solution with Quickwatch window is here:
Open Quickwatch during Debug mode
Type in your Variablename and press Enter
Press CTRL + A and CTRL + C in order to select and copy all Properties. You need to expand those which contains values and are non primitive types.
Paste to your favorite editor.

Related

Visual Studio option to turn a written code block into a method?

A while ago I was watching a video where the presenter cleaned up his code by highlighting already written code, and choosing some option that converted the code into a method. It also automatically recognized what parameters needed to be passed, and all he needed to do was name the method.
Does anyone know what this option is called? I have looked all over and cannot find it. I can't remember the video either.
It was probably refactoring. Highlight your code, right click and select "Quick Actions and Refactorings", then select "Extract Method". (Or choose Edit Menu > Refactor > Extract Method.)
You'll be able to change the name of the new method. Visual Studio does its best to figure out what types are needed as parameters, what should be returned, what visibility for the method is needed, etc. You'll still want to double check the result and make sure it does what you want.
Yes, it's called refactoring your code. You can extract a method by right clicking on the highlighted method and choosing Extract Method from context menu. VS will extract the method and set the parameters for you.

VSIX: Adding a Menu Item to the Visual Studio Editor Context Menu

I have an internal extension I'd like to add to Visual Studio that should hook up to the Editor Context menu - regardless of what type of file is open. I can handle enabling/visibility dynamically but essentially I'd like it to be accessible on any type of editor file.
I've not been able to find the right parent command/group ids to manage to get a custom button to display on the editor context menu. I suspect there's not a single Id but several but any guidance on what I should be looking at. Having a hard time figuring out what the proper parent command Id is to hook up to the editor context menu.
Specifically I need to be able to add View in Browser option to files that Visual Studio doesn't recognize as HTML/Web files (even though they are mapped to the appropriate editors).
Related: Is there anyway to reasonable way to discover the menu command and group names? Poking around in the SharedCommandPlace.vsct is as close as I've come but even that is proving to be very difficult to match to actual menu items.
I was able to figure out the right command groups for the context menu. It turns out the various editors all use separate context ids and so have to be managed as separate menus so this gets messy quick.
Steps
I used the HKEY_CURRENT_USER\SOFTWARE\Microsoft\VisualStudio\14.0\General key and EnableVSIPLogging value of 1 to enable logging.
I then navigated into the editor and with the mouse on an empty area press CTRL-SHIFT and then right click the mouse
This gives the info a menu group like and it looks like this:
---------------------------
VSDebug Message
---------------------------
Menu data:
Guid = {D7E8C5E1-BDB8-11D0-9C88-0000F8040A53}
GuidID = 358
CmdID = 53
Type = 0x00000400
Flags = 0x00000000
NameLoc = ASPX Context
---------------------------
OK
---------------------------
The important values are the GUID and the CommandID.
Add the Guid and Command ID under Symbols like this to register the command set mapping the Guid to the CommandSet and the CommandId to the context menu values:
<GuidSymbol name="aspxContextCommandSet" value="{D7E8C5E1-BDB8-11D0-9C88-0000F8040A53}">
<IDSymbol name="aspxContextMenu" value="0x0035"/>
</GuidSymbol>
Note that the value maps to the CommandID represented as a hex value.
Then reference this group as a parent for your command group (MyMenuGroup) in the Groups section:
<Group guid="guidViewInBrowserPackageCmdSet" id="MyMenuGroup" priority="0x0000">
<Parent guid="aspxContextCommandSet" id="aspxContextMenu"/>
</Group>
You reference the menu group you create for you command buttons and point at the context menu created in the previous step.
If you want to do this for multiple editors (ie. the ASPX, HTML, and Code editors for example as I do) you repeat this process for each of your editors by adding both the GuidSymbol and the Group.You'll end up with multiple Group entries for the same MenuGroup point at a different parent and all will activate appropriately.
Works great, but you'll probably have to make sure you filter your OleMenuCommand objects with a BeforeQueryStatus event handler to ensure the menu shows only when you actually can handle.
I needed the same thing and I used:
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_CODEWIN"/>
So, I just changed the id. See: https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.vsmenus.idm_vs_ctxt_codewin.aspx
The EnableVSIPLogging registry value still works for VS 2015. You just need to add an EnableVSIPLogging DWORD set to 1, under HKEY_CURRENT_USER\SOFTWARE\Microsoft\VisualStudio\14.0\General.
If the CTRL+SHIFT + menu popup or menu select, doesn't result in that dialog, chances are the menu item in question is not implemented as a VSCT resource.
That being said, you may need to experiment a little, as editor and designers are not required to use the same context menu that the code editor uses.
Also, you might want to try out Mads "Extensibility Tools" extension at https://visualstudiogallery.msdn.microsoft.com/ab39a092-1343-46e2-b0f1-6a3f91155aa6 (2017) or https://marketplace.visualstudio.com/items?itemName=MadsKristensen.ExtensibilityEssentials2019 (2019).
He's added a nice autocomplete for VSCT files that's pretty useful.

Looking for constant values for DAO.Field.Type

I have need of using VBS in conjunction with the DAO.Field.Type methods and properties. Since I am using VBS I do not have access to the constants displayed on this page and I can't find a good resource that will tell me what they are.
Most specifically this MSDN article lists the constant names, but I don't know what their values are, and I would appreciate finding out what they are.
Field.Type Property (DAO)
Thanks,
Sean W.
Do you have Microsoft Office? Here's one way you can find them.
Open any Office product.
Hit ALT+F11 to open the VBA editor.
From the Tools menu, select References....
Find the reference entitled Microsoft DAO X.X Object Library, check it, and click OK.
Hit F2 to bring up Object Browser.
In the top drop-down, choose the DAO library.
In the 2nd drop-down, type your constant name (e.g., dbBigInt) and hit [Enter] to search.
Select the proper item from the search results.
Near the status bar is a pane that describes the selected item. It will show you the constant's value.

Modifying VB6 control properties from text editor leads to unexpected behavior

So I'm writing a script to modify quickly a VB6 application's interface with COM controls. (Created in C# .net). Most of it works fine, but some panels are giving me a lot of trouble.
Basically, I open the .frm file and read it, and when I find some controls I modify their values or insert new things. When I find a panel, I create a different panel around it so it looks better. I'll put, say Top = 2340 in the file for my new element. If I open the .frm in notepad, I can clearly see that the value of Top is at 2340. Once I open VB6, the panel's top value is at Top = 8190. It also modifies the Left value, but nothing else. If I save and exit vb6, then reopen the .frm in notepad, the Top value will be saved at 8190.
Why does VB6 uses different values than the ones in the .frm file? Is it trying to avoid elements stacking on top of each other ? What is happening between reading the file and opening it, that forces a different value of the Top property?
Just a theory, but I believe the issue is that the ScaleMode property isn't setup right. By default, unless the container window has the property, it'll be set to Twips. So what may be valid under certain containers won't be valid in other containers.
The MDIForm container, for example, forces Twips, and may even re-position objects based on alignment.
If this is the form itself, which I don't think it is but worth mentioning, make sure the StartUpPosition is properly set to 0 (Manual).

When I am looking at a method that is called on an interface, how do I go to the code the implements the method?

We have lot of code like:
IPerson
{
Eat();
}
Persion : IPerson
{
}
IPerson p;
p.Eat();
As most of our interfaces only have 1 or 2 classes that implement them, there should be a way for me to right click on the “p.Eat()” and be taken to the code the in person class. When there is more than one implementer, I wish to be shown a list to choose from.
There is a new feature in Visual Studio 2010, called View Call Hierarchy (Ctrl+K, Ctrl+T).
Right-click on a symbol in code (method name or properties are good) and select View Call Hierarchy, and you will get a new window with various options. On interface members, you will see an 'Implements [member]' option, dropping this down will show you all instances where the interface member has been implemented.
Similar options appear for virtual / abstract members, showing you where they are overridden or implemented.
As an extra bonus, this window also shows 'Calls To [member]' and 'Calls From [member]'.
Resharper is an extremely valuable refactoring tool which provides the behaviour you describe.
I currently right click on the method name in the interface file and select the option 'Go To Implementation'.
I'm assuming this is a Resharper feature and not just Visual Studio 2010 purely because you aren't aware of it. Try right-clicking and seeing if you have the option. If not - I highly recommend getting a refactoring tool with this kind of functionality.
Edit | Find and Replace | Find Symbol will find definitions and references.
Right click on p.Eat() and choose "Find all references". In the Find Symbol Results windows, you may find all of the implementations of that interface method. Double-clicking each item will show up the reference in code editor.

Resources