Home > Mobile >  Suppress all warnings of a method
Suppress all warnings of a method

Time:05-31

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.

CodePudding user response:

To disable all warnings for a single method:

#pragma warning disable
void MethodWithWarnings()
{
   ...
}
#pragma warning restore
  • Related