Can I change the Designer.cs file?

Resharper directs my attention to this line of code in Form1.Designer.cs:

private System.ComponentModel.IContainer components = null; 

... with "Field can be made read-only"

Is it safe to agree, or should I just write it down so that Resharper is too overpredicted and ignores it?

Resharper also contains Designer.cs flags for many other violations, for example:

Create Redundant Explicit Delegate

and, several times:

Check this. is redundant

UPDATE

This is what my settings look like (I didn’t change them):

enter image description here

So ... does this mean that I need to manually add all these file extensions that were seen during Yigal Tabachnik's scream? It seems to be configured only for Windows 8 projects; the quick and dirty trick that threw these messages is a regular old Windows Forms application.

+4
source share
3 answers

It is safe to modify the Designer.cs file, but I would not recommend it. The file will be automatically generated and it will be generated again when you modify the file of the corresponding forms. At the top of the file, mention this in a comment: All changes will be lost .

+4
source

These warnings from Resharper are recommendations not rules. They are read-only code and help prevent accidental coding errors, making your intention more obvious.

Now the Designer.cs file is generated by the machine and is intended to be read by the machine, and not for humans, therefore these recommendations do not apply to the designer file.

I was 90% sure that the filters in Resharper excluded the Designer.cs design code from it, but I had to wait until Monday to check. You can simply add a filter to your Resharpers settings to exclude *.Designer.cs

+4
source

You must somehow change your Generated Code option in ReSharper, since ReSharper always ignores known generated files and regions by default, so it should not .Designer.cs any violations in any .Designer.cs files.

Make sure your settings look like this:

EDIT : for some reason, most of your defaults are missing. The best you could do is try to reset the default settings.

The fastest one is to remove GlobalSettingsStorage.DotSettings located in %appdata%\JetBrains\ReSharper\vAny , but this will obviously reset all your other settings (such as user name conventions).

Alternatively, you can manually edit the file (it is just an XML file) and delete all lines starting with:

 <s:String x:Key="/Default/CodeInspection/GeneratedCode/GeneratedFileMasks... 

After deleting the entries, save the file ( make a backup first! ) And restart Visual Studio. Your defaults are expected to be returned.

+4
source

Source: https://habr.com/ru/post/1488957/


All Articles