- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.4k
Avoid casting Enumerable.Empty to IList #3836
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
Conversation
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.
Looks great! One nit, and I'm auditing the other uses of Enumerable.Empty<T> in our codebase to see if anything else looks fishy.
| _loadedProjects.TryGetValue(fullPath, out List<Project> candidates); | ||
|  | ||
| return candidates ?? (IList<Project>)Enumerable.Empty<Project>(); | ||
| return candidates ?? (IList<Project>)Array.Empty<Project>(); | 
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.
Can you also remove the now-unnecessary cast?
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.
No, because candidates is a List<Project>. I get this error: Operator '??' cannot be applied to operands of type 'List<Project>' and 'Project[]'
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.
Ah, makes sense. My toy test project didn't use ??.
| The bad assumption (that  | 
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.
Thanks!
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.
Looks good, thanks!
Fixes #3834.