How to avoid all code nodes to expand on project opening? - c#

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.

Related

Can VS Intellisense be configured to run "to-cursor"?

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 :)

How do I view form code history?

I'm working on a C# desktop application for a class, using Visual Studio Online source control system. It gave me a choice of Team Foundational Server or Git, and I choose Git because I've heard of it and my professor recommends it. This is my first time using these features and I'm finding them a little confusing.
I can view the history of most of the files I'm working with, and revert to old versions, but I can't seem to do that for my form code. I think it has to do with what files are attached to source control, indicated by the blue lock icons.
Here's a screenshot of what I'm talking about:
I would like to be able to see the history of Production Buddy.cs, what am I doing wrong here? I can see Production Buddy.Designer.cs's history, so I may be not fully understanding what's going on here.
Thanks!
The screenshot shows there was neither red tick or blue tick. Which indicates that the file was not under source control. This happened may be because you copy pasted the file or the solution was on offline mode or solution file was updated when you took latest which replaced the entry of Production Buddy.cs file, and since it was not on the server there was no server history for that file.
I would recommend using Source Control Explorer when you have to compare the files.

How to change formatting options based on solution

My boss set our IDEs up to use non-standard formatting. For example, it adds spaces between the parenthesis and parameters. This is fine for the new stuff that we've started from scratch, but it's super annoying when I go into existing projects and try to format the code with Ctrl-k-d because when I go to compare the file with the latest version before checking in my changes it looks like I've changed almost every single line in the file and it's difficult to pick out the actual changes.
I would like to be able to use his settings in the newer development, but switch to the default settings when working with other projects. Is there a way to accomplish this without having to go into the settings and uncheck/recheck all the appropriate options every time?
EDIT: I understand it might be good to reformat all legacy code to use the new standards. Unfortunately, that's not my decision to make. And even so, I sometimes work from my personal computer which I also use on occasion to do contract work for other companies. I obviously can't reformat their code to fit my bosses standards.
You can easily switch between settings, by creating separate .settings files and using a VSIX package to switch between them by loading them into Visual Studio - I use this for switching between Dual and Single monitor settings via menu items in the Tools menu.
Using an extension is annoyingly complex for such a simple operation, and this was a whole lot easier when Visual Studio supported macros. However I've uploaded my homebrew extension to GitHub in case you want to have a look.
The tricky bit is editing the settings files to only contain the ones you're interested in, which I expect are the ones in Text Editor\C#\Formatting\Spacing.
The Rebracer extension stores code formatting options alongside each solution and when you open a solution, Rebracer will automatically apply that solution's settings.

Is it good practise to remove Id tags from Controls that I don't reference in Code Behind

I'm wondering about a feature in Visual Studio. Personally it bugs me when I open a solution someone else has been working on and it's full of Controls with Ids like "label27" "textbox3" etc.
One of the first things I do is either rename them or remove them if they are never referenced in code behind (as is usually the case with the labels).
But I was just wondering why Visual Studio defaults them such meaningless values, then I started thinking if maybe it is better practise to have something in the Id field rather than blank it.
Of course the best situation is to give them all sensible names, but if I come across a project full of those auto generated Ids, am I doing the author a favour by removing them to "clean up" the solution?
I used to think so, but wouldn't the default for dragging and dropping or copying and pasting controls in be without an Id?
I think there's no reason to keep IDs like that. More ids => more html => more size. I know, this may be not significant, but why to plague your source code with something you don't want and don't really need?
If you don't like VS's default behavior, you can disable "auto id-ing" via settings:
Tools -> Options -> (Show all settings) -> Text editor -> HTML -> Miscellaneous
VS will assign ID automatically to the controls you haven't provide them to. But if you are pasting some code with controls without IDs, VS will add autogenerated names to them.
So, Microsoft thinks that all the controls should have uique IDs. And you should provide such IDs. But if you really don't need them, so simply remove ID to adjust readability to your code.
The main point is this should be for all controls accross the project, and it should be easy to read "clean" code.

Visual Studio - Tool to replace hard coded strings with resources

I have a big ASP.NET project full of hard coded strings, that now have to be extracted to resources. Such strings can be found almost anywhere (in .cs files, .aspx files, .ascx files, etc.) and the amount of files is huge. What I'm looking for is a tool (or any way) to find all these hard coded strings in one shot and put them all together in the resource file, instead of me going manually through each file. Does anything like this exist?
Note: I'm aware that it would have been better to put the strings in resources straight away when they were needed the first time, but this is a 2 years old project where nobody really cared (typical example of "not my problem" philosophy).
Thank you very much.
UPDATE: I tried CodeRush (I couldn't try RGreatEx for obvious reasons), and I'm having difficulties using it. The main issue is that the strings I'm looking for are located mainly in .aspx files, and strings in those files don't have the "Refactor to resource" command available.
For example, I can have elements like this:
<dxwgv:ASPxSummaryItem DisplayFormat="{0}" FieldName="TOTAL" ShowInColumn="Total" SummaryType="Sum" />
The part I need to change is ShowInColumn="Total" and make it like ShowInColumn="<%$ Resources:PortalResource, Total %>". This is not a string assignment in a strict way, but an attribute assignment, so the "Refactor!" command of CodeRush doesn't appear.
My target is to find all of them in one shot and change them in a specific interface (i.e. like a localization tool) instead of looking for them one by one and manually creating the corresponding resource. Refactoring one by one inside each file would be an improvement, but still very time consuming...
You could take a look at the resource refactoring tool at
http://www.codeplex.com/ResourceRefactoring
It's an instance-by-instance tool rather than a batch replacement tool. It's free and standalone so you don't need Resharper or Coderush.
Check out the new open source project VisualLocalizer on CodePlex: VisualLocalizer page. If you have some ideas, post them as issues - the project is under development and we welcome feedback.
VisualStudio lets you search and replace with RegEx. It won't be the "fix all in one shot" solution, but it should cut back on the amount manual work significantly.
Just a thought.
If you have a look at DevExpress' CodeRush it has the functionaility you are looking for, you may need to automate it to do it a all in one shot.
It has a great deal more too!
Kindness,
Dan
Try RGreatEx. This is a plugin for ReSharper:
RGreatEx is the most powerful localizer and coding helper for Visual Studio. Once installed, it lets you localize .NET applications and produce safer code, saving up to 95% of time the developer usually spends on doing the same by hand. Empower yourself with time-saving refactorings, such as "Move to resource" and "Rename resource". The plug-in will automatically analyze string and resource usage and suggest moving strings to resources.
Do you have ReSharper? Then you perhaps should wait for version 5.0. It will have RGreatEx (mentioned by Anton) functionality included. Read the thread from the R# forum on this topic.
Update: The feature will be in R# 5.0. See the official announcement.
I've just published new tool called Jinnee.Package for string refactor. You can find it on Visual Studio gallery:
http://visualstudiogallery.msdn.microsoft.com/7ec5a225-dea4-47ae-8ebc-450d2980937f?SRC=Home

Categories