views:

1444

answers:

5

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:

  • Here is a link to the error on MSDN.
  • I've already tried both Shadows and Overrides and neither eliminates the warning.
  • The warning isn't on the method itself (unless Shadows or Overrides are omitted), but rather it's on "Implements System.IComparable.CompareTo" specifically.
  • I am not looking to suppress all warnings of this type (if they crop up), just this one.

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.

A: 

On the properties of your project, go to the build tab and use the suppress warnings textbox.

Hope it helps, Bruno Figueiredo http://www.brunofigueiredo.com

Bruno Shine
I am not looking to suppress all warnings for this project, just this one.
Sean Gough
You wouldn't be suppressing all messages since you can specify with message codes to suppress. Check my response down below.
Bruno Shine
A: 

Add the keyword Shadows to the function definition.

Public Shadows Function CompareTo(ByVal obj As Object) As Integer Implements System.IComparable.CompareTo
JaredPar
Tried both Shadows and Overrides, neither remove the warning unfortunately.
Sean Gough
A: 

Rather than suppressing the warning, shouldn't you be fixing it? Assuming that the base is Overridable,

Public Overrides Function CompareTo(ByVal obj As Object) As Integer Implements System.IComparable.CompareTo

If not, then shadow it,

Public Shadows Function CompareTo(ByVal obj As Object) As Integer Implements System.IComparable.CompareTo

(I think this is correct, I am a C# programmer. If not, please comment and I will update.)

Rob Prouse
Tried both Shadows and Overrides, neither remove the warning unfortunately.
Sean Gough
A: 

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.

Bruno Shine
A: 

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
Topi