views:

38

answers:

1

On a continued mission to clean up the codebase I inherited, via stylecop and fxcop, and one of the warnings from fxcop was CA1801: Parameter 'value' of Something.MyProperty.set(string) is never used. Remove the parameter or use it in the method body.

The code it complains about is:

public class Something : ISomeInterface
    public new string MyProperty
    {
        get
        {
            throw new InvalidOperationException("MyProperty is not implemented.");
        }

        set
        {
            throw new InvalidOperationException("MyProperty is not implemented.");
        }
    }

This property is defined in the interface, but in this case is not needed in the derived class - Aside from the slightly questionable use of InvalidOperationException instead of NotImplementedException, which I believe is common, I wonder if I should just exclude the warning in FXCop with a note explaining why?

I don't see what else I could do do in terms of best practice, to prevent the warning in FXCop, other than refactoring this particular property out into a second interface, and then updating all the other classes that use this interface? I think I may have just answered my own question? :D

+2  A: 

I believe it is because of the "new" keyword that you are receiving this warning. Try replacing removing new with override and see if the warning disappears.

public class Something : ISomeInterface
    public string MyProperty

BTW, I recommend using NotImplementedException instead of InvalidOperationException as well.

Lucas B
Actually, changing it to override did seem to solve it, but not entirely sure I understand why! :D
Andrew Johns
In addition, this required the base property to be defined virtual in order to be able to override it.
Andrew Johns
@Andrew, Ahh.. sorry I missed this. Since it is an interface you can just remove new. New will create another method signature and not implement the interface.
Lucas B