I guess a lot of people start working on something. And then later they find-out the names don't really cover the end product. Or well at least, I do choose often poor names for stuff, I start programming faster then thinking about things like that (in the end I often rename my buttons too so my code becomes more clear too).
What is the best way of a current work in progress (not finished) to rename it? Without breaking the code, or do a lot after editing.
The reason I ask it here is I've seen it gone wrong a few times, leaving me code that didn't work any more so I better as how to do this and where in which pane, it's best to rename.
So what's wrong? Well in the upper right pane of Visual Studio 2010 C# (solution explorer):
The solution itself has a wrong name
The next line of it has the wrong name
And the main form could be improved too
If you were to rename the main form it would ask you if you want to change all references to it, you say yes and that problem is solved.
Renaming the solution is equally simple, just right click in the Solution Explorer and rename. It won't break your local build or anything.
I don't know what "The next line of it has the wrong name" is referring to (the project maybe?) but the same probably goes for it.
Well usually you should change the file name of your class in the solution explorer and it should ask if you want to change all references, though sometimes it can go wrong so to double check you can replace all command to find all references of old name and replace with the new one..
http://msdn.microsoft.com/en-us/library/139eef4h.aspx
Also if you change in code, the name of a class or variable or anything and then you should see small line under the changed name, stand with the mouse pointer on the variable and press ctrl+. (ctrl dot) And that shoul pop up small options and the first one should let you change all references of that variable new name also:
http://www.dofactory.com/ShortCutKeys/ShortCutKeys.aspx
Related
When typing multi-line comments Visual studio used to add an automatic asterisk to each new line of the comment as I press enter(apparently 2015 does not do this anymore). I really liked this. As of right now though, if I type "/*" and enter, Visual studio does not try to autocomplete it at all. In fact, it even lets me end the comment with "*/", too, instead of doing it for me. So my question is: is anyone else experiencing this? How do I get the original functionality back, so each new line is automatically prefixed with an asterisk, and closed for me by "*/"?
I already checked and yes, my environment settings are set to C# and yes the option "Generate XML documentation comments for ///" is indeed checked in my settings.
This is a well-known problem, the feature fell by the way-side in the Roslyn refactoring of the C# Editor Features. Nothing to do with config or a change of preferences, it simply was not implemented.
It is currently being tracked by this Github issue. Status is "Up for grabs" right now with nobody having shown an interest in grabbing it yet as of today. Afaict, best to not hold your breath for it, I think they have several bigger fires to put out. It will surely be delivered in an update sooner or later.
Just wanted to update and say that this problem was apparently fixed(sort of) in one of the newer updates of Visual Studio. The editor still does not complete the comment for you, but it does at least keep the formatting consistent, and adds an asterisk to the next line for you.
At the moment I have to write C# code in VS2012, (Before was: Java (Eclipse, IDEA)).
May be I am strange guy, but I like when class name == class file name.
Why in VS2012 no option to rename class file same as I renaming class name? (Or I could not find it)
I know that C# compiler do not care about matching class name and class file name, but I want to do it. I can`t find class by its file name if they are not same, it is annoying me very much aaaargh.
Help me please, I'm tired finishing work after VS
If you rename the file first, Visual Studio will usually offer to rename the class to match.
I'm not sure what the exact circumstances are, but if you're sticking to a single class per file it'll work most of the time.
You could use ReSharper. This plugin has option to rename file to match the class name.
It is a feature that VS sadly does not have. You can supply with a few refactoring plugin, like Resharper or CodeRush or Refactor! Pro...
They all come at a price and with their own fan base. CodeRush as far as I remember as a free version with very limited features, but maybe the "Rename File" is among them, you would need to try.
Another option would be to find an extension (or develop one) that does that for you, just head to the Visual Studio Gallery to find one. =)
You just point to the object you want to change, right click and use Refactor -> Rename. A popup refactoring window will appear. Choose your options and click "ok".
To address this line from Rawling's answer (since I don't have enough rep to just make a comment):
I'm not sure what the exact circumstances are, but if you're sticking to a single class per file it'll work most of the time
To clarify, Visual Studio will offer to rename and refactor your class when you change the file name as long as the class is defined within a namespace. If you've chosen not to use namespaces, you won't have access to this IDE nicety. This is true up to at least VS 2017 Pro (the newest as of this answer).
I work a lot with WPF, and have lots of files in a project which makes navigation sometimes a bugger. I tried to write a macro that helps me at it, but I haven't managed doing so far after struggling a few hours. And not using VB at all, it makes it a bit harder. Maybe someone can push me into the right direction, or help me out to accomplish it.
What I try to achieve is the following macro:
Retreive the selected text
-> CType(objDocument.Object, EnvDTE.TextDocument).Selection
Check if the word starts with 'Controllername'
-> text.Startswith("Controllername"))
Remove double qoutes
-> Text.Replace(Chr(34), "").Split("/")
Search for the file in the project where the function is located
Go to the line number of that function
The reason why I want to create this macro is because of the fact that in WPF, I use actionlinks which refer to a "controller/action", which is in stringformat. With this macro I could select the "controller/action" text, hit the keybinding, and go to the function (or display an error for instance if it doesn't exist).
Thanks for the input in advance! :)
At some point "Find All References" feature got broken for a single solution that I have. It works in all other solutions. For this one, it always returns "Search found no results"
What could be the problem?
In the old days (VC6 :) ) this type of problem was often fixed by deleting the .ncb file and letting it be rebuilt automatically. Not sure if this is still true in VS2005/8.
I would kill all instances of Visual Studio and try again. If this doesn't work, I would imagine that there really are no references to the type or member you are looking for.
Since this feature is working for other solutions I find it hard to believe that this is an issue with the IDE itself. I think the most likely explanation is that the IDE is correct and you actually have no references.
Do you have two types that are similarly named but not actually the same type? Can you find the references by text search?
Had the same problem in VS 2008. In my case it was because I was opening the web site as a project, instead of doing File - Open Web Site.
For me, I have been stumbled by "Search returned no results" but quickly realized that method name was Finalize(). Once renamed, all was well.
I am currently developing with VisualStudio 2008. I find it increasingly difficult to find files when the number of files and projects increase. The situation become so bad that I literally have to spend 10-20 seconds to find code I want to work on when switch between files. Sounds like not a lot of time, but this can be very annoying because it breaks the "coding flow".
I believe this is a general problem with all IDEs. But I still find it easier to work with Eclipse. One particular example is that in Eclipse, I could apply some key shortcut to find implementations defined in an Interface.(I have forgotten which key shortcut though, after not working with it for about 1 year.) Another example is that in VS 2008, rightclick->Find all references will find all occurrences containing the selected text(Update: This accusation is incorrect. Thanks for pointing it out); while similar operation in Eclipse will find all occurrences where the selected class/variable are referenced. Personally, I find the Eclipse way is better for file navigation.
This could be due to my inexperience with VS IDE. So, I am looking for suggestions to improve the file navigation experience so that I can get some more time for actual coding.
I have used the navigate buttons but they are only useful for small number of files.
Thanks.
I agree wholeheartedly about ReSharper. If you don't want a "paid" solution though, a useful Visual Studio shortcut is
CTRL + ,
it gives a list of recently edited files.
CodeRush is a free alternative to ReSharper which you might find useful too.
Kindness,
Dan
Have a look at Jetbrains Resharper. Ctrl N or Ctrl Shift N. To jump quickly to files by type name or by file name. Also you can control Click Classes to navigate to them instantly.
I can't even work in visual studio without it anymore. It virtually eliminates the need for the solution explorer
SamTools for Visual Studio 2005/2008 (and I have a build for 2010 if someone needs it). The particular feature that's handy here is the Solution File List.
You can right click the tab of any open document and Find In Solution Explorer or Show In Windows Explorer
You can right click in the Solution File List for the same
Unlike other solutions to this problem, this is a properly docking tool pane so it fits in great. Ctrl+Alt+F places you in the Filter box with the current text selected, so it's very easy to work with.
Oh and it's free/GPL. :)
Solution File List http://wiki.pixelminegames.com/images/8/88/SamTools_SlnFileList.png
Dpack is also a free alternative with some nice file navigation shortcuts, but Resharper is the bomb.
BTW, they should have some more of this stuff in vs2010, which is in beta right now (I think)