Here is my problem. I have a C# class file loaded in Visual Studio that I am working on. I made a class and created some properties inside of said class. I collapsed the properties like so:
I collapse the properties with the little +/- button on the side of each. I want to collapse each of them since I have a lot of other classes with properties and I don't want to see a lot of repetitive code (get, set).
Closing them works fine but after I work on some other classes in the same file the properties re-open so I can see the code:
This happens relatively often and is quite annoying. I have a lot of lines in the file and I sometimes have to work with a small screen. Is this a glitch/bug or something else? (I am using Visual Studio 2010 C# Express)
Thanks for your help.
There is no way to solve this so far, but this does the trick. Press CTRL-M and then O and it will auto collapse everything in the current file you are on.
An alternate tip to #DJKRAZE's excellent answer is Resharper. I use Resharper and it takes care of this automatically for me. For example if I write this code:
The 4 line property procedure causes a Expand/Collapse that is causing you grief.
Resharper makes it one line. When I delete the last curly brace (namespace) and enter it again, the code is automatically formatted (Edit > Advanced > Format Document doesn't do this):
You can use this:
#region some_name
//your variables or code whatever
#endregion
And then you can collapse the particular code, and the good thing it does not open like the way it happens in your case.
See if that worked.
Related
I work on reality big project. And sometimes i get the need to search for some specific keyword inside A single c# file that has many calls of other functions from other c# file.
So i want to know if there is any easy way that could search for give phrase or keyword inside the current file and inside all the functions that my current file calls to. But not in the entire solution or inside the whole project.
For inside the file that's Ctrl+F.
Otherwise Code Search in VS2022 is very fast. Normally it's bound to Ctrl+T.
Introducing a New Way to Search Your Code and Visual Studio Features
Code search in Visual Studio 2022 is about to get much faster).
There also are the Go To options in the context menu that could help:
Finally, at the top of the editor window you can switch between classes and properties/methods.
BTW. You can address the large solution problem by splitting the codbase into multiple smaller solutions that only include parts of the overall code. This has some drawbacks, but overall it works very well in my experience.
I use both Delphi and Visual Studio (C#), and I've noticed a difference in how code-completion works which I find really annoying. In Delphi, if you edit existing code so that you change the variable you're using, code completion will give hints based on the code before your cursor. For instance, inserting an "I" into myString to become myIString would give a code hint to show any available variables starting with "myI". Selecting one will then overwrite myString with the new one.
In Visual Studio doing the same thing brings up a code-completion menu with all available variables, and none selected so you see the top of the list. You have to completely delete the variable you're using and start again before you get meaningful code completion.
I seem to make changes like this quite often (maybe I should just get it right in the first place!) so it gets a bit annoying having to remove code, and can be trickier on longer lines with lots of parts to them.
Here's some screenshots which (hopefully) illustrate the difference. I was struggling how best to word this!
Code completion in Delphi
Code completion in Visual Studio
I've tried playing with the Intellisense settings in Visual Studio and there's nothing there which seems to change the behaviour. Is there any way of replicating it in C#?
I've tried playing with the Intellisense settings in Visual Studio and
there's nothing there which seems to change the behaviour. Is there
any way of replicating it in C#?
For now, VS doesn't support for this behavior. The auto completion won't work when we insert a character into existing variable. It will take effect when we type a character in a empty place.
Type character in a new place, the intellisense works.
Insert character,the intellisense not works.
In my opinion your suggestions is really meaningful. I think it could be better if we have a new option to support for auto-completion when insert character, so I suggest you can Go=>Help=>Seed Feedback=>Provide a suggestion to post your idea there.
We who interested in it will vote for you if you share the link here.
As alternative ways:
You can go Tools=>Options=>Text Editor=>C#=>Intellisense=>Enable Show Completion list after a character is deleted option.
Then you can insert 'i', the statement could be myiSring1.GetType(); And delete any or all characters in the String1,it would show the intellisense like below:(e.g:I delete 'r'.) Apparently, this is what you really want, but as I mentioned above, VS itself doesn't support this behavior for now, hope you can use 'delete option' saves some time. Sorry for the inconvenience.
Also, you can check if ReSharper can meet your needs,since it's a third-party tool which seems to charge after xx-days trial, I have no further details for it.
Hope all above helps :)
A property was added to a custom user control. Since then, Visual Studio has inserted generated code to every form that uses that user control. Now we want to remove that property because it is not going to be used. But obviously doing so causes compile errors. Is there a way to tell Visual Studio to remove the property from all that generated code? It seems to me that putting something like [Obsolete()] should be enough to tell Visual Studio to remove it from the generated code. Is there some other way?
Look at DesignerSerializationVisibilityAttribute, especially the DesignerSerializationVisibility.Hidden option.
Caveat: Unfortunately you will have to open every form/control in design mode so the code can be regenerated (if it does not do so already).
Regex to the rescue! What I usually do is open Replace in Files dialog (Ctrl+Shift+H), check Use Regular Expressions checkbox and replace instances of .+\.SomeProperty.+ with empty string.
Be sure to commit your changes to repository before this, so you can revert to working state if anything goes wrong.
You can try to use some refactoring tool, like Resharper.
http://www.jetbrains.com/resharper/
Adding the "Obsolete" atribute will only generate a compiler warning, but wont remove any code.
Just leave it and mark it as Obsolete.
I have a C# project and some code pages have few thousand lines of code. I really like the idea of nodes in the code editor. I use it a lot and create many regions. But every time I open the project, all the nodes are expanded and I have to minimize them manually. It gets really annoying.
I have not found any help about this on internet nor in the options of VS. There must be a setting somewhere.
In the Options dialog onder Text Editor --> C# --> Advanced, there is an option "Enter outlining mode when files open". This should be checked.
In the IDE, from the Tools menu click Options. Alter default Outlining using
TextEditor->C#->Formatting->Advanced
There is a checkbox here you can use to set defaults for Outlining. This is VC# 10 Express but similar in other versions.
If you try the suggested change, you may be disappointed. According to this C# PM, who's responding to a similar complaint:
It is a bit confusing, but the
behavior you're seeing is intended.
The feedback that we received with VS
2003 was that we should persist the
outlining state of source files after
they have been closed and then
reopened. The option in Tools |
Option now effectively means what the
default behavior should be for a file
that you have never opened before. It
has no effect on files that you have
opened previously, since those files
already have a persisted outlining
state.
I don't want be a smart ass here, but often if you have that huge code in one file, you have more than one logical unit and might be able to (ans should) split it. (Single Responsibility Principle).
For my share, I don't like the regions because they are hiding code and I prefer to see all of it.
I am looking for a way to extract a nested inner class so that it is in a separate file. Is there an easy way to do this in Visual Studio 2008 (eg, using the refactor menu)?
EDIT
Maybe a refactoring menu option isn't necessary if manual refactoring is simple enough.
if i understand correctly, you can use partial classes
http://msdn.microsoft.com/en-us/library/wa80x488(VS.80).aspx
I don't remember there being a built in refactoring for that, but it is available in Resharper. If you don't have Resharper and have a lot of them you need to refactor, you could always download and use the trial.
DevExpress offers a free coding assistance tool called CodeRush Express which offers this refactoring. Here's a link to the page showing the refactoring.
I own a license to their full-blown CodeRush w/ Refactor Pro, and I love it.
EDIT
Following the edit of the question, I just wanted to add that I'm able to do that refactoring using the following keystrokes (with the cursor on the name of the nested class)
Ctrl+` (opens refactor menu)
Enter (or arrowing down to the option if it's not already selected)
That automatically creates a new file in the project with the name of the nested class as the name of the file, moves the nested class to that file, removes it from the original location, and drops a marker at the place where the nested class was removed. Hitting Esc takes you back to where the extracted class was removed.
It is a huge time-saver. Granted, my day's not full of extracting nested classes, but it's an example of how saving a couple of minutes here and there can really help remove the friction from some common development tasks.
This question is a bit outdated, but I found a very good solution since Visual Studio 2017:
If you have a nested class, place your cursor on the class name. A little screwdriver appears on the left side (alternative press CTRL + .).
In the context menu you can select "move to myClass.cs".
Now it will refactor your nested class in a seperate file with all namespace changes.
Here is how it looks: