开发者

FXCop warning CA1801: "Parameter is never used..." on overridden inherited supressed property

On a continued mission to clean up the codebase I inherited, via style开发者_开发问答cop 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜