Enable intellisense for inactive code region - c#

Looking for tips regarding doing C# with visual studio.
I need a way to enable intellisense for code between pre-processor #if/#endif.
Normally such code is greyed out, How can i disable this greying out.
Even though the code is not being compiled i still need intellisense on the code.
Cheers

Actually, if you want to get the intellisense for the gray part, you only have to make the condition of the gray part to be true. And there is no other way to realize it.
If you use the pre-processor in a specific configuration, you can try the following two suggestions to get the intellisense.
Suggestion
In my side, the test is defined under DefineConstant of Debug.
1) change the condition of the two parts and when you modiy the first part, make the condition of it to true.
2) or create a new Configuration called Test which does not have such pre-processor and when you modify the gray part, just change to Configuration to Test, and then you can modify the gray part.

Related

VisualStudio highlights all my code green, I don't know how to disable this effect/feature

I was writing the code normally and then I fear I have accidentally pressed some shortcut that made my code all highlighted green, I tried to press some combos but nothing changed, I deleted the script from Unity and pasted the code into a new script, and it gave me the same issue. If I press anywhere it doesn't change anything and it only disappears for a moment when I edit the code and then it goes back to being green. I imagine this feature has a purpose that I'm not understanding but at the moment it's not doing anything for me except making the code less readable. Does anyone know what caused this effect, how can I remove it, and what is it's purpose? Thanks for your help.
You can also check the theme here:
Maybe you turned on "Toggle Code Coverage Highlithing" under Tools menu.
If it looks something like this then you've probably added the files to your project without adding them to git. The green indicates added but unstaged changes. Do you see plus signs in the ruler?

Find all unused code in my project (Rider/VSCode)

Goal
Ideally, our projects contain no unused namespaces / methods / functions and classes.
It is fairly simple to find the number of usages of all of these, for instance;
Has two usages while the following class is never used:
Such code can remain unnoticed for quite some time, while providing unwanted overhead to the total solution.
What I'd like to achieve is an overview of all unused code, so developers can easily assess what should and shouldn't stay in the solution.
Question
Of course we're not going to manually search for these...
How can we find all unused code?
To find unused code in Rider:
Select Code | Inspect Code in the application menu.
Choose a scope to inspect (solution, project, or a custom scope).
In the Inspection Results window, group inspections by issue category (and optionally by issue type).
Focus on issues under Redundancies in code and Redundancies in symbol declarations:
Alternatively, as you read or edit your code in the editor, you may encounter specific unused code warnings that Rider shows you. If you want to find all issues similar to one specific issue:
Press Alt+Enter to display Rider's code inspection pop-up.
Press Right arrow to expand options for the current inspection.
Press Right arrow to expand the Find similar issues submenu.
Select a scope to find issues.
Work with the Inspection Results window as shown above.

How to turn off "Qualifier 'this.' is redundant" warnings in Resharper?

In my code I have a lot of this. qualifiers (a habit from writing Python code), so I have a lot little orange warning markers in the right hand gutter saying "Qualifier 'this.' is redundant". I don't want to remove the this. qualifiers. How can I turn off the orange warning markers?
For Resharper 9 it's been moved. Actually I never noticed in Resharper 8, because I use "this" for clarity. My problem is that now it's all over the place and it drives me insane. I hope this helps someone, because it took me some time to find this.
Change your settings in the Inspection Severity section. In the C# tab, there is a section called Redundancies in Code. In there is a Redundant this.' qualifier setting. I put mine on
"Do not show" (gray-colored).
The following is taken from the comment by #user2864740, which the OP found to solve the problem:
It should be possible to open up the ReSharper context menu - click on
the pencil thing to the left when the warning is "in focus", or
perhaps hit Alt+Enter (?) - and select "Change Inspection Severity..".
It should provide several options from Ignore to Error. I believe
there is also an inspection option to Require the this. explicitly,
but I've never felt inclined to look for or enable it. (Such an option
would likely be within the main Code Inspection R# options.)
If you don't have the ($$$) Resharper, you don't need it to remove the orange warning markers or the lightbulb suggestions. You can do this within VS 2015: Follow exactly this set of instructions in the green-checked answer, but tick the "Qualify member access with 'this' " instead. Click OK, and you'll never see another this lightbulb again.
I don't know if this particular configuration is available in other VS versions, but at least you can check your version.
OR, apply the change globally (project-wide or solution-wide) with one click as demonstrated here:
And you'll never see it again in your project.

How to enforce Type Members Layout setting in ReSharper?

In Resharper -> Options -> Code Editing -> C# -> Type Members Layout it is possible to set up a custom layout of members in types.
This is all very cool, but is there a way for ReSharper to display a warning if the layout is mismatched? It could work exactly the same way as with all other Resharper-detected violations - a yellow bar could be displayed in the scrollbar and I would immediately know something is wrong.
As far as I know, the only thing you can do right now is run Code Cleanup on your code files (either as a batch or one at a time). If you have your settings correct, this will fix any out-of-order members.
If you just want to receive a warning but not actually fix the issues, however, I think you are out of luck (at least as of version 7.1.3).
If you use StyleCop with ReSharper, ReSharper will underline the warning/error from StyleCop. It says to me that the order isn't right.

Completely remove "error list" from visual studio

I want to completely remove "error list" from visual studio 2008, not disable it i want it gone. It annoys me to no end popping up endlessly, i guess i must be "doing it wrong" but w/e i just want to use VS without being alerted every other keystroke about some warning.
I've tried editing many different fields in the options (tools -> options) it has only slightly decreased the frequency of the error list popping up. I have also deselected errors, warnings, and Messages. and it pops up with nothing to display. unpinning it doesn't help either.
also upgrading to VS 2010 is not an option at this point.
Im looking for a solution something like the following: remove a dll or config file responsible for this
Also I still want the inline validation (the little squiggly marks, etc), but
the error list window annoys me.
I think this is probably exactly what you're wanting:
http://blogs.msdn.com/b/zainnab/archive/2010/05/16/hide-or-show-error-list-when-the-build-finishes-with-errors-vstiptool0022.aspx
You can change this behavior by going to Tools -> Options -> Projects
and Solutions -> General and deselecting the "Always show Error List
if build finishes with errors".
I'm guessing this will work with ASP.Net as well, since that's building on the fly.
I am using Visual Studio 2017, and I also have to cope with the useless, impossible-to-disable, annoyingly-in-your-face, and outright disturbing "Error List" window.
So, here is what I did:
Undock the "Error List" window to make it free-floating.
Resize it to the smallest size possible.
Move it out to some remote area of the screen where it is not so annoying.
And voila, problem solved ! (*1)
*1 Well, problem mostly solved. It will be completely solved when I abandon this dinosaur of an IDE.
My 'Error List' was constantly displaying also (VS2012). I also hate it.
I turned it off years ago, but today it just started appearing.
It was being caused a unreadable packages.config file. For some reason that reports it's fail state through the yukky 'Error List'.
Fixing the packages.config file stopped the 'Error List' from appearing.
for VS2017, select the "Build only" value from the drop down list in Error tab. Refer to the image below:
Hope this helps!
On Error tab, you have Errors / Warnings / Info buttons. Click on Errors button (de-press).
hope it helps.
I suggest turning off inline validation.
Yes, I know that you still want it. But, seriously, how important is it? It's trying to validate code that is half-written. How valuable can that be?
First of all, as-you're-typing code validation is distracting. It makes it harder to focus on the problem you are trying to solve. For example, writing a function with a non-void return will display the "not all code paths return a value" error continually until you get to the end of the function. In the meantime, the editor is telling you that there is a problem. I am sure that people learn to ignore these things over time (I have never kept the feature on for more than a few minutes after a new VS installation, so I don't know), but if you are actively ignoring something, then what good is it?
Second of all, any good that the validation would be capable of is unnecessary, because those errors will be brought to your attention at compile-time anyway. Having an uninitialized variable pointed out to you while you are thinking through the algorithm does not improve the quality of the code at all verses having it pointed out when you try to run the program. The variable is still going to be initialized either way. And there is an extremely high likelyhood that you are going to fix the problem before trying to run the code anyway.
So I just don't see the point of it. I suggest turning it off, and then your problem goes away.
UPDATE
As pointed out by #Charlie Kilian, there is a flaw in VS in which .aspx files are not validated at all, unless the "Show live semantic errors" option is enabled for C#, rather than validating those pages at compile-time as would be expected.
Therefore, editing aspx files will require turning this option back on for validation.
I guess I'll be going back-and-forth with it from now on. I hope they fix this in future versions of VS.
I still think that doing a semantic analysis and error-reporting on code that is actively being edited is a fool's errand. (Of course, I have also been known to write entire programs in notepad, just to see if I could get it to compile and run correctly the very first time without the crutch of Intellisense. It feels pretty awesome when it works.)
Selected answer is incorrect because unchecking "Always show Error List if build finishes with errors" does nothing to stop the dreaded Error List window from popping up on other errors, even if you change it to show only Build errors.
11 years later in Visual Studio 2022 it is still impossible to disable Error List window.
The only correct answer to the question "Completely remove error list from visual studio" is to uninstall Visual Studio itself which, thankfully, also removes Error List window.
Either that, or we should all get used to it, because Developer Gods from Microsoft want everyone to work in absolutely the same way as they do. Every workflow that differs from their own is wrong, and every thought that doesn't align with their grand vision is blasphemy.
It is One Microsoft Way or the highway.

Categories