-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correct zero length check expressions #16463
Conversation
This pull request has merge conflicts. Please resolve those before requesting a review. |
@gvkries feel free to leave code review and approve PRs when you visit them |
@@ -111,7 +111,7 @@ private async Task<IEnumerable<ContentTypeDefinition>> GetContainedContentTypesA | |||
{ | |||
var settings = (await _contentDefinitionManager.GetTypeDefinitionAsync(contentType))?.Parts.SingleOrDefault(x => x.Name == partName)?.GetSettings<FlowPartSettings>(); | |||
|
|||
if (settings?.ContainedContentTypes?.Length == 0) | |||
if (settings?.ContainedContentTypes == null || settings.ContainedContentTypes.Length == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI I checked if the more succinct items?.Any() == false
pattern would work. It wouldn't, as it (I don't understand why) produces null
; and it also violates CA1860, nudging you towards items?.Count == 0
. So, that's not an option.
I noticed many invalid expression used in OC when checking for a zero elements in a collection.
Here is explanation
@Piedone it would be nice to add an analyzer to guard against such a count check. Maybe related to #7950