Thursday, December 10, 2009

No warning on missing comments

By default if documentation is enabled, Visual Studio will give you warnings for each public class, method, field and so on that’s not documented. This is certainly useful for places where you’re writing some complex logic, but for some other places in your code and for generated code documentation isn’t always necessary. You can let the compiler ignore certain warnings for specific parts of your code by adding a pragma to your code file.

Pragmas are a way to communicate with the compiler from your code. C# have it as well though the standard compiler (csc.exe) only understands two commands, warning and checksum.

The code below has a pragma added that tells the compiler not to raise warnings with id 1591 (missing comments)

   1:  #pragma warning disable 1591 

To re-enable this warning after a code-block, you can add following pragma:

   1:  #pragma warning restore 1591 

No comments: