The if keyword in the following statement is underlined in green by ReSharper:
if (readOnlyFields.Contains(propertyName)) return false;
return base.CanWriteProperty(propertyName);
ReSharper suggests the following change:
return !readOnlyFields.Contains(propertyName)
&& base.CanWriteProperty(propertyName);
Why is this "better"? I find the current code more readable and the result should be the same as far as I know. Any thoughts?
Neither one is better in the sense that either one will perform better than the other. (Any difference is going to be entirely negligible.)
Certain coding conventions suggest that you use one return statement per function so that it's easy to understand it's flow. It's not a hard and fast rule though and in this case it's pretty obvious what's going on. If you don't like it's suggestion but you would like to ensure that your code is easily read by others I'd suggest the following:
if (readOnlyFields.Contains(propertyName)) return false;
else return base.CanWriteProperty(propertyName);
But your way is fine too.
On the quick fix menu (Alt+Enter), there's a "Correction options" (or something like that). You can turn this specific suggestion into a hint, or turn it off entirely.
On a personal note, I prefer your original over ReSharper's suggestion.
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