Find method in current file/class in VS2015/C# - c#

I can use the Ctrl+, shortcut to search for methods but will search among the entire project:
This lists all the classes in all files that have this method, and I want to search only in the current file, similar to Alt+M in VAssistX. Is there a shortcut for that?
I found Is there an easy way to jump right to a method within a file?, but it's for VS2012, and they only suggest Ctrl+F or Ctrl+,.
Note: I'm looking for true navigation, not Ctrl+F, and only within the current file, unlike Ctrl+,.

To expand on the answer by Matt Schley:
Ctrl + F2 -> Tab -> then start typing and it'll sift through the functions in the file.
I know you were probably looking for something else, but this is as good as it gets for what's built into Visual Studio. Maybe there's extensions available.
EDIT
This is a mapping for C#. The command name is Window.MovetoNavigation
For C++, it's default is Ctrl + F8

Not sure if this is what you're looking for, but there is a dropdown menu right above the code editor window that lists all methods and properties in the current file.
Try Ctrl + F2 to active the navigation bar, then tab over twice and you can scroll through the dropdown.

For VS2019 you can use Alt + \ for object search.

From https://learn.microsoft.com/en-us/visualstudio/ide/go-to?view=vs-2019, it says Ctrl+1, Ctrl+M for Go to the specified member. You can add your own combination to this command by going to Tools -> Options -> Keyboard and choosing Edit.GoToMember. For me it works just perfect.

Related

Refresh start menu icons in Windows 8

I have an application that works weirdly: the setup process copies the files to a temp folder, then checks a few things, and if everything is ok, moves the files to the final folder.
The problem is that the installer creates the shortcuts before the files are moved.
The result is that on the start menu (the one with the tiles), the icon is the "default sortcut" one.
I have tried to force the refresh of the system using this link (broadcast a WM_SETTINGCHANGE message) but it doesn't seem to work for the Windows 8 start menu.
Even rebooting the OS doesn't seem to refresh the icon, the only thing that works is to reinstall the soft on top of itself.
How can I force the icons refresh for the Win8 start menu ?
Thanks
First off, you don't tell us why your install process needs to work the way that it does. I agree that's weird, but I assume you have a good reason for doing it that way. If not, I suggest starting there and fixing the installer rather than putting band-aids on individual problems. You're bound to run into other problems later, and the root fix is bound to be much simpler and easier to maintain than a bunch of band-aids.
Anyway, if you must go down this path… The reason that broadcasting a WM_SETTINGCHANGE message doesn't work is because this doesn't have anything to do with icons. Those are managed separately by Explorer and don't get rebuilt unless you delete its icon cache. That, naturally, prompts it to rebuild it. It's a common troubleshooting technique for end users, but it's not something you want to do programmatically. Talk about an ugly hack. And altering the global state to solve a local problem.
Besides, if rebooting the OS doesn't work, you know it's not as simple as you make it sound in your question: a property in need of a refresh. The reason that reinstalling on top of the existing installation works is because when the shortcut gets created in the beginning, its target executable already exists in the expected place (put there by the previous installation) with a valid icon.
What I recommend doing is writing some code to change the icon of the existing shortcut. Make sure that you execute it after you've copied the executable file to its final destination. The method that allows you to do that is IShellLink::SetIconLocation, which takes two parameters: a path to the icon (this would be the path to your executable file), and the index of the icon (this would probably be 0 assuming that the icon you want is the first and only one contained in the executable).
Of course, in order to call SetIconLocation, you're going to have to obtain an object representing your shortcut that implements IShellLink. This is a COM interface, which I don't believe is wrapped anywhere by the .NET Framework. General information on creating shortcuts from C# is available in the answers to this question. More specifically, there's a link to this wrapper class that you can use to do most of the dirty work. I don't think it contains a method for setting/changing the icon, but that can be trivially added.
Alternatively, you can get at these same properties using the Windows Scripting Host (WSH) wrapper, WshShortcut. It has an IconLocation property that works much the same way except that it takes only a single string argument, with the index delimited from the path by a comma: myApp.exe, 0. It's not particularly well documented (best I can find), but to get an existing shortcut, you just use the CreateShortcut method and specify the path to the existing shortcut. For example:
public void SetShortcutIcon(string shortcutPath, string iconPath, int iconIndex)
{
// Note: no error checking is performed for the parameters!
// This is not production-ready code!
// If a shortcut does not exist at the specified path, you should
// create a new one instead.
// If iconPath does not specify a valid executable file, you should
// set a default icon or perhaps abort.
IWshRuntimeLibrary.WshShell wsh = new IWshRuntimeLibrary.WshShell();
IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(shortcutPath);
shortcut.IconLocation = String.Format("{0}, {1}", iconPath, iconIndex);
shortcut.Save();
}
Note that in order for the above code to compile, you will also need to add a reference to the Windows Script Host Object Model to your application. To do this, right-click on the "References" folder in the Solution Explorer, click the "COM" tab, and find "Windows Script Host Object Model" in the list.
I just tested this and it works; the effect is instant.

Universal change of namespace across projects

We have a solution with ca. 60 projects.
The standard we have used for namespaces is CompanyName.ProjectName.Area.VisualStudioProjectname.
Now the project has changed name.
Is there a way to change the name of the namespace across all projects, wcf services and service references?
We have ReSharper if that could help.
There are different ways u can achieve this result.
Beginning from ReSharper version 5.0 and above u can simply use
ReSharper -> Refactor -> Adjust Namespaces...
but in your situation I do not think this is what u are looking for.
There is another solution as well simply open one of your code-files select portion of the namespace u want to change hit CTRL + R + R and then rename. it will go through all your project files and adjust and rename new namespace.
the same result can be achieve to update them fairly quickly through the Class View window. Open class view window, click on the namespace you want to rename, hit CTRL + R + R and then rename.
as u mentioned you are using ReSharper so u have everything u need to get the result.
How about a good old Edit / Find and Replace / Replace in Files?
ReSharper -> Refactor -> Adjust Namespaces might do the trick.
Possibly a good use for the Block Sync Edit Visual Studio extension.

Visual studio autocomplete to find a file?

In the Visual Studio, do we have a tool to find a file based on file name insdie a project, like typing a few letters of beginging of a file, it will autocomplete to show all files starting with that letters. In the Java Eclipse, we can use Ctrl+Shift+R , do we have similar in the VS ?
Thanks
Yes, there is something like that.
You can use the Find text box you use for normal searches as input for the Command Window. Then in the Command Window you have the of command to search files.
To do it:
CTRL + /to select the Find text box.
Type > of then the file name (or part of) you want to search for.
A dropdown list will show all files that match your typing (so you do not have to know the full file name as with CTRL + SHIFT + R).
If file list is pretty long you may use the normal Find in Files dialog, simply set Use to Wildcards, in Find what type * and write the search pattern in Look at these file types. Check the Display file name only option. Using the Look in field you can limit the search to current project, entire solution or whatever you need.
Try ctrl-spacebar, it's the normal shortcut for intelisense. If it doesn't work for file path and name, there is surely a plugin out there just for this.
I use VS with only resharper as a plugin and I can do this, I don't know if its resharper that does it or if its prebuilt.
EDIT: It is resharper that does it. I would recommend using it if you intent to work with VS as it greatly helps out on a lot of refactoring and shortcuts.

Create custom right-click context menu item with C# for all desktop shortcuts (windows explorer)

The problem is easy: I've a lot of desktop shortcuts which points to a lot of file, BUT I also have a lot of shortcuts which points to directories pointed by those shortcuts. I want to remove this redundance by simply adding another rightclick menu options for all shortcuts (.lnk files) that allows you to open explorer.exe to the directory containing the file pointed.
While I discovered how to retrive the target of a shortcut and it's working, I found a suggestion on how adding a menu item to rightclick context menu, but it's not working (I put a key under HKCR*\shellext\ContextMenuHandlers called Test and set the base value to "cmd.exe"
But it doesn't work, obviusly
any suggestion?
Update 1:
How to add an icon to that menu item?What size should the icon file have? 16x16 or 32x32?
thanks in advance
Go into HKCR\lnkfile
Create a new key called "shell", and below that create another key called whatever you want the display text to be for your context menu handler, I called mine "COMMAND".
Next, create yet another key below that called specifically "command" and make the (Default) value be "cmd.exe", which will be the path to your custom command. Remember to wrap it in quotes if you're going to be pointing to an exe that has spaces.
So for this example, the final key ends up being:
HKCR\lnkfile\shell\COMMAND\command\
Add the (Default) value mentioned above and your test will be working fine.
Additionally, you can use "%1" to specify the full path to the .lnk file being accessed by the context menu, again remember to wrap it in quotes since you never know if it'll be a file that has spaces in it's full path.

Visual Studio Format entire file?

Is there a way to issue a key command to properly format an entire file in VS2008 with CodeRush Express?
Use Ctrl+K+Ctrl+D to format document keystroke
Use Ctrl+K+Ctrl+F to format selection keystroke
It's also possible to set your own keystrokes by opening Options... dialog (select Tools->Options from the menu). In Options dialog select Environment->Keyboard form the tree and set your own shortcuts for Edit.FormatDocument.
You could always go to Tools -> Options -> Keyboard and give the Edit.FormatDocument a new shortcut.
Update You can also see what the Shortcuts mapped to this command are this way.
Ctrl+K,Ctrl+D
This question with answers has a lot of handy tips.
If Ctrl+E+Ctrl+D or Ctrl+K+Ctrl+D or Ctrl+K+Ctrl+F doesn't work for you, try to set below settings:
Tools->Options -> Text Editor ->C# ->Tabs,
make sure `Keep tabs is selected.
Then, go back to your text editor, re-try formatting.
I was really annoyed before, and steps above works for me. hope it works for you guys..
Just select all content of page by Ctrl + A then click Ctrl + K and Ctrl + D.
The whole page tag format.
For example see this link:
Format the content
Shortcut in visual studio to format the whole document is Ctrl + E, D
I just use built-in Visual Studio formatting command: Ctrl+A, Alt+F8
Ctrl+E+D in Visual Studio Express 2013.

Categories