Overriding a property from an abstract class

Hi,

In an abstract class, R# is warning that "Only overrides of property ExpenseAccountCaption are used

public abstract string ExpenseAccountsCaption { get; }

"Removing the unused property" of course breaks the classes that have overriden this property.

Surely, this should not be a warning?

Regards
Jeremy



            
2 comments
Comment actions Permalink

Hi Jeremy,

I could  not reproduce this problem. I created the following example:

using System;

namespace ClassLibrary1
{
  public abstract class C
  {
    public abstract string ExpenseAccountsCaption { get; }
  }

  class D : C
  {
    public override string ExpenseAccountsCaption
    {
      get { throw new NotImplementedException(); }
    }
  }

  class Client
  {
    void Foo(D d)
    {
      Console.Out.WriteLine("d.ExpenseAccountsCaption = {0}", d.ExpenseAccountsCaption);
    }
  }
}


The property in class C is highlighted as you wrote but applying the quickfix to remove it gave the following result:

using System;

namespace ClassLibrary1
{
  public abstract class C
  {
  }

  class D : C
  {
    public virtual string ExpenseAccountsCaption
    {
      get { throw new NotImplementedException(); }
    }
  }

  class Client
  {
    void Foo(D d)
    {
      Console.Out.WriteLine("d.ExpenseAccountsCaption = {0}", d.ExpenseAccountsCaption);
    }
  }
}


which is correct and compilable.
0
Comment actions Permalink

It does seem rather odd that you would define an abstract base member but then not call it - so the warning is not unreasonable, in my view.

It's not really any different to many of the other 'this thing is not used' warnings that you get, other than removing it is a bit more complicated than merely deleting it.

0

Please sign in to leave a comment.