Skip to content
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

Add missing null check operator in ShellSettingsManager.EnsureConfigurationAsync() #12328

Merged
merged 1 commit into from
Sep 5, 2022

Conversation

hishamco
Copy link
Member

@hishamco hishamco commented Sep 4, 2022

No description provided.

@hishamco hishamco requested a review from jtkech September 4, 2022 17:19
@hishamco hishamco merged commit 7f95dc0 into main Sep 5, 2022
@hishamco hishamco deleted the hishamco/shell-settings-manager branch September 5, 2022 21:08
@@ -239,7 +239,7 @@ private async Task EnsureConfigurationAsync()
.AddConfiguration(_applicationConfiguration)
.AddSourcesAsync(_tenantsConfigSources);

if (lastProviders.Count() > 0)
if (lastProviders?.Length > 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take care of this kind of changes, here that's okay as we are using > 0.

But we could have used !=0, in which case it would have been wrong.

        int? test = null;
        if (test > 0) // This is evaluated to false.
        {
            ;
        }
        else if (test != 0) // But this is evaluated to true.
        {
            ;
        }

That's why it's safer to use test != null && test > 0 or test.HasValue && test.Value > 0.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think actually this is a new code recommendation from Visual Studio to change .Count() to .Length in some places.

Copy link
Member

@jtkech jtkech Sep 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is better, no problem about changing Count() to Length, I was talking about keeping the previous behavior when dealing with nullable types, here with the .? operator.

@hishamco hishamco added this to the 1.5 milestone Sep 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants