In the following code example, R# will tell me that the assignment is redundant. Which makes perfect sense to me.
private string _name = null; // Redundant code warning
However, things are different, as soon as the field / property gets protected or higher
protected string Name = null; // No Redundant code warning
Is this a bug in R# or is there a reason behind?
It's because without looking for deriving classes, ReSharper can't tell if it's used or not, so it errs on the side of caution and assumes it is used, somewhere. If you enable Solution Wide Analysis, ReSharper will be able to see the whole solution, and will know if the field is used in a derived class or not. Then it will show the redundant code warning.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With