"Auto-property accessor is never used" warning from ReSharper

9.9k Views Asked by At

Our Application is an MVC Application . I tried to run code analysis using ReSharper. I am getting "Auto-property accessor is never used" as warnings in many of my view model properties.

For example, ReSharper shows the warning on this:

public bool IsLegalEntry { get; set; }

Can I make a private setter, or can anybody suggest an alternative?

2

There are 2 best solutions below

0
Rachelle On

You could make the setter private

public bool IsLegalEntry { get; private set; }

However, this could cause a runtime error if the setter is used implicitly. Alternatively you could decorate the setter with the JetBrains.Annotations.UsedImplicitlyAttribute.

public bool IsLegalEntry { get; [UsedImplicitly] set; }
2
Sergiy Yeskov On

Alternative to "warning fixing/suppressing" paradigm, you can add testing project to your solution. Then write a test for you business logic hitting the accessor(s) in question among other things.

Not sure this is the action you were looking for, however

  • it provides the effect you were after
  • saves for redundant annotation attributes
  • adds testing bonus