Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Suppress all warnings of a method

What is the easiest way to suppress all warnings from Visual Studio (and possibly Roslyn Analyzers) for a certain method? Like I copy-paste code from a stackoverflow answer into a new method of my class and the code doesn’t comply with my coding guidelines but also I don’t want to change it and I don’t want to insert lots of pragma warning disable directives or lots of SuppressMessage attributes.

Regarding ReSharper warnings I can simply add the following attribute to the method:

 [SuppressMessage("ReSharper", "All")]

but this works only for the ReSharper warnings, not for those from Visual Studio.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

To disable all warnings for a single method:

#pragma warning disable
void MethodWithWarnings()
{
   ...
}
#pragma warning restore
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading