I have a class that inherits from a base class and implements the following...
Public Function CompareTo(ByVal obj As Object) As Integer Implements System.IComparable.CompareTo
Now the base class it inherits from also implements this System.IComparable.CompareTo so I'm getting the following compiler warning:
Warning: 'System.IComparable.CompareTo' is already implemented by the base class. Re-implementation of function assumed.
I'm fine with that so my question is how can I suppress this warning for just this function (i.e. not all such warnings).
Clarifications:
Solution:
I was hoping to use the System.Diagnostics.CodeAnalysis.SuppressMessage attribute or something like C#'s #pragma but looks like there's no way to suppress the warning for a single line. There is a way to turn this message off for this project though, without turning all warnings off.
I manually edited the .vbproj file and included 42015 in the node for Debug and Release compilations. Not ideal but better than always seeing the warning in the IDE.
If someone has a better solution please add it and I'll gladly try it flag the answer.
Some warnings are suppressed by default. To override this, use the --strict_warnings switch to enable all suppressed warnings. By default optimization messages, that is most of the messages between 1593 and 2159, are not warnings. To treat optimization messages as warnings, use the --diag_warning=optimizations option.
You can suppress violations in code using a preprocessor directive, the #pragma warning (C#) or Disable (Visual Basic) directive to suppress the warning for only a specific line of code. Or, you can use the SuppressMessage attribute.
If you want to turn it on (or off) in the project setting, you have to go to: Configuration Properties -> C/C++ -> Command Line and then under Additional Options you can enter: /w3#### to set your warning to level 3, and thus enable it; or you can enter /wd#### to disable a warning.
Only use 'Implements' in the base class:
Signature in the base class:
Public Overridable Function CompareTo(ByVal obj As Object) As Integer Implements System.IComparable.CompareTo
Signature in the inherited class:
Public Overrides Function CompareTo(ByVal obj As Object) As Integer
You can use the supress warnings just to suppress one warning. See here for more on how to. You can also use the SuppressMessage Attribute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With