Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Redundant code detection" works differently on protected or higher scoped properties and fields

Tags:

c#

resharper

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?

like image 414
CSharpie Avatar asked Dec 19 '25 23:12

CSharpie


1 Answers

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.

like image 97
citizenmatt Avatar answered Dec 24 '25 11:12

citizenmatt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!