Hide specific code lines starting with {string} in Rider - c#

I find that a lot of the telemetry code that I write often creates a lot of noise in my code files and is generally a bit of a nuisance. I'm looking for a way to hide specific lines in Rider if they start with a specific string.
For example if I had a lot of lines in my code that started with
_telemetryClient
Is there a way for me to turn off hiding and unhiding these lines?
I'm aware that #region exists, but Rider doesn't provide any hotkeys or quick ways to wrap code in a region and hide it. There's a menu you can click in the gutter but it's messy and ends up introducing empty lines for no reason.
If my request isn't possible, is there a way I can create a macro so that I can highlight a block of code and run the macro so that it automatically wraps the code with region tags, names the region and folds it?

Related

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.

Enable intellisense for inactive code region

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.

C# Visual Studio 2015 - Automatic jump into brackets

This is my first question on stackoverflow, so here goes:
I've got this annoying problem/feature in Visual Studio 2015. The problem is every time I create an if statement, for, while, etc. with autocomplete (tab-tab). When I then go to the line of the end bracket and try to create a new line (simple press of Enter) right after it, my text cursor will immediately jump into the brackets, instead of making a new line.
I've looked far an wide as for trying to disable this "feature" as it is incredibly annoying. But I have not been able to find any information on it anywhere, so now I am asking you all this question.
Thank you!
How I produce the problem:
Anywhere in a C# project, make a new if statement (while, for, etc. can be used too).
Navigate to just after the end bracket.
Press Enter to make a new line.
The marker will have jumped to the inside of the statement, instead of making a new line.
The 'problem' is that when using the tab key you are activating the snippets feature. After typing tab you are in 'snippet editing' mode, where each tab (and shift + tab) are used to navigate the placeholders defined by the snippet. In snippet mode, the Enter key always takes you wherever the person who designed the snippet thought it was the best place to leave the cursor after that snippet. For the if snippet that happens to be inside the brackets.
The good news is that you can create your own snippets, and even modify existing snippets to change their behaviour. However, as far as I know this involves manually editing snippet definition files (xml files) or using external extensions. For example: http://blogs.msdn.com/b/visualstudio/archive/2014/01/15/visually-creating-snippets.aspx
As a workaround, you can also just press Esc to exit snippet editing mode before pressing Enter.

Recover code deleted by Visual C# Form Designer?

So, I made a program in Visual C# 2010 Express. Finished enough to work, and pretty darned good for my first attempt at the language. But then I foolishly decided, "Hey, this program needs a close confirmation dialog before I send it out!" So I write the function, and then I go into the auto-generated code to bind said function appropriately.
KABOOM!
Now, the form designer shows a blank form, and all those shiny components have all been erased from both the designer and the auto-generated code. Which, in such a simple program, is about 80% of the work I put into it.
Now, in NetBeans, I would right-click the file's tab, and just go back to a previous version, maybe losing about 15 minutes of work. This is a pretty obvious concept, I'm just not sure where to find file history in Visual Studio. So, where is the equivalent so I can get my work back?
(I've also managed to get my code back by just undoing a whole bunch - but the designer doesn't see it, and neither does the compiler, so it still builds to a blank form.)
Sadly, you've just learned a couple of things.
One is to never, ever modify designer-generated code. In fact, C# has a concept called partial classes which allow you to modify a generated class without having to modify the generated file.
Second, that Visual Studio in and of itself has no built in source code control -- you need to choose the one you like and be diligent in using it. Some of the most popular are git, subversion, mercurial, and Team Foundation Server. I personally use svn, but the others are good too. Avoid something called Visual SourceSafe (VSS).
From the sound of it, I'd say you tried ctrl-z until some point in your code, but not in the designer?
Performing multiple "undo's" in the code-behind file where you put your code is one thing, performing "undo's" in the designer is another.
Hopefully, you have not closed visual studio yet, and viewing your now blank form in design view, and trying a bunch of ctrl-z presses there, might do the trick.
Actually the controls are not lost from Design code or Initialize
Component() ,make sure that whether check
Initialize Component() { this.controls.add("Where the control was ")
}
Example:
1-this.Controls.Add(this.panel1.label1); 2-this.Controls.Add(this.panel1.label2);
either in form you can write like below
should write in the Initialize Component()
this.Controls.Add(this.label1);
I had a similar effect: the code wasn't lost because the project compiled perfectly but I only got a blank form in designer.
This was because the form was inherited from another form, and I added in the Load event of the base form the line: this.MdiParent = Application.OpenForms("BaseForm");
After deleting this line (and recompiling) I could access the design of the descendig forms again.
One thing you could do, it won't help you this time, but may be a good idea for the future - if you copy your code alot (like I do), get one of those clipboard savers - like ClipTrap (which is lightweight, simple, and great).
Then, if you realize you can't undo what you did, then you get a second chance by running through the "trapped" text to see if what you want might just be there.
Another good option is to try something like AutoVer, which will save a copy of any changed file (or files in a folder) every so often as you like. This could provide you with a backup of your codefile, or even the entire project - every five minutes, or every minute as long as something has been changed. Awesome program. This is a certain fashion of source control, or at least source backup.
(And no I'm not the authour of either application)
However, for your particular problem, if the code is still there in your designer.cs page - maybe you just erased a reference or a namespace. Make sure the namespace matches, and make sure your in your form's code file, that the InitializeComponent(); function is being called (that's what places all the designer's controls onto the form, you know).
In the code behind file click 'undo', not in the designer window. Accept the warning, and when the code comes back, the form should be back to normal, Visual Studio 2015.

saveFileDialog Long Wait on "Okay" Confirmation

I'm writing in Visual Studio 2008 using C# (if that makes a difference) and I have the following snippet of code:
if(saveFileDialog1.ShowDialog() == DialogResult.OK)
{
//Write Stuff to File Here
}
For a while I thought my code that wrote the file was taking forever, however upon debugging it seems to take forever (5 to 10 seconds) just to step between the "if" statement and the first bracket of first code within the "if".
Is there anything I'm doing wrong? Is there any difference between creating the saveFileDialog object in the UI versus creating it on the fly (through code)? Would it make a difference if there is no "else" statement?
Any thoughts or ideas would be greatly appreciated!
This is not unusual, on many machines a ton of DLLs get loaded into your process when you use that dialog. You can see them getting loaded by using Project + Properties, Debug tab, tick the "Enable unmanaged code debugging" checkbox. The Output window shows a trace of every DLL that worms its way into your program.
These are shell extensions, customizations for Explorer. The dialog you use is a shell dialog, you surely recognize the similarity with regular Explorer views. Things like icons and context menus behave the same. Having a lot of shell extensions installed is common on developer's machines, more so than user machines. There are a lot of them out there, offering such conveniences as integrating whatever tool you like to use with Explorer itself.
Debugging the problem isn't that easy, you won't have the actual source code for these extensions. You might get a hint about the troublemaker from the trace in the Output window. If there's a lengthy pause after one particular DLL then odds are good that this DLL is the source of the problem. Nothing really solid though.
The better approach is to use SysInternals' AutoRuns utility. It shows you exactly what shell extensions are installed and allows you to disable them by simply clicking a checkbox. Start disabling anything that doesn't have a Microsoft copyright and stuff you could live without. Logout + Login required to make the changes effective.

Categories