In Visual Studio Professional 2010 whenever I type the following:
new {
It automatically changes to:
new object {
Is there a way to make it not do this? "Object" does not have the properties of the object I want to anonymously create.
https://connect.microsoft.com/VisualStudio/feedback/details/584429/autocomplete-on-new-is-interpreted-as-a-new-function-instead-of-anonymous-class
I'm pretty sure it's a bug, so I went ahead and reported it. Was going to do it sooner or later anyway :)
Hope that's okay with you.
You can disable the IntelliSense completing when you type the bracket.
On the Tools menu select Options. Then, on the right hand side, expand Text Editor then C# then IntelliSense. Remove the { from the textbox under the Committed by typing the following characters:
You may also have to uncheck the Committed by pressing the space bar or get in the habit of writing new{ and relying on the auto formatting when you close the bracket (though I've never done any ASPX stuff so don't know how good the auto formatting is compared to a normal code file.)
I've just gotten in the habit of typing "new{}". Intellisense doesn't kick in then. And since I'm always reformatting the page anyways with crtl-k;crtl-d, it spaces it out correctly later on.
Related
New install of Visual Studio 2022 - NET 6 project.
In the past, the variables (in the pic below) would have little squiggles underneath them and when I hover the mouse over them a suggestion would pop up stating something similar to (names are not cased or capitalized correctly). It was like the IDE had a code analyzer (maybe an extension/addon) that constantly monitored coding styles.
After installing VS 2022 I cannot figure out how to make these types of suggestions appear. Can anyone help me with this?
Edit - Additional info
I think, maybe it's rule IDE1006 that I am trying to activate in the IDE
Also, in (Tools)(Options) I have these settings. But not a single notification about variable names that violate IDE1006
I can see all of these notifications too (pic below), so, I know with certainty the code is being analyzed (the analysis is just not pointing out (variable name) violations)
There is a setting for enabling and disabling specific style guidance selections.
You will need to navigate to Tools/Options/Text Editor/C#/Code Style/General
In addition to catching flat out syntax errors, Visual Studio does have code analyzers.
This feature still works. Looking at your image, it appears there are those dotted lines under offet_A and offetBecause. It's hard to know exactly why because I don't have enough context of the few lines we're looking at.
I do know that method names starting with lower-case letter generally trigger this warning, but again, we can't see if you have that going on either.
So my answer is this feature is still active. But it only happens for naming that violates accepted naming conventions.
I edited my .editorconfig file (added the lines below), and now the Style Rules, specifically (IDE1006 naming rule violation), etc are enabled/flagged in my source code
dotnet_naming_rule.locals_should_be_camel_case.severity = suggestion
dotnet_naming_rule.locals_should_be_camel_case.symbols = locals_and_parameters
dotnet_naming_rule.locals_should_be_camel_case.style = camel_case_style
dotnet_naming_symbols.locals_and_parameters.applicable_kinds = parameter, local
dotnet_naming_style.camel_case_style.capitalization = camel_case
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.
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.
I am in a view editing HTML and I may for example need one line of C# code inside <% %> tags..
If that C# code contains a bracket like { or } after I press enter or complete the command, VS automatically spreads the line over 2 lines to kind of auto-indent the brackets.
It's really annoying because I am not in code view, I just want my view to look super clean and therefore keep the C# indentation exactly how I typed it in.
Any idea how to disable this???
Many thanks..
Every Visual Studio auto-indent operation is being saved in the Undo history. This means that if you press Ctrl+Z (undo) immediately after the auto-indent, it will be canceled and the code will be reverted to the initial indentation. This undo operation will not affect any characters that you have entered, only the auto-indentation.
It is still annoying, since it requires an additional keyboard input, but for many situations it is a good enough workaround.
Yeah, I've experienced that too... Hate it when VS does that. But the only way to do it, that I know of, is disabling C#'s "Automatically format completed block on }"...
Go to Tools | Options | Text Editor | C# | Formatting | General and uncheck it.
BUT you will lose this feature for all C# code (not only in views)...