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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/OrchardCore/OrchardCore/Shell/ShellSettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.

{
configurationBuilder.AddConfiguration(new ConfigurationRoot(lastProviders));
}
Expand Down