Use is null/is not null

This commit is contained in:
Tyrrrz
2021-03-09 21:57:26 +02:00
parent ebe4d58a42
commit 3aef7faa1e
17 changed files with 59 additions and 59 deletions

View File

@@ -20,7 +20,7 @@ namespace DiscordChatExporter.Gui.Behaviors
var behavior = (MultiSelectionListBoxBehavior<T>) sender;
if (behavior._modelHandled) return;
if (behavior.AssociatedObject == null)
if (behavior.AssociatedObject is null)
return;
behavior._modelHandled = true;
@@ -43,7 +43,7 @@ namespace DiscordChatExporter.Gui.Behaviors
_viewHandled = true;
AssociatedObject.SelectedItems.Clear();
if (SelectedItems != null)
if (SelectedItems is not null)
{
foreach (var item in SelectedItems)
AssociatedObject.SelectedItems.Add(item);
@@ -56,7 +56,7 @@ namespace DiscordChatExporter.Gui.Behaviors
private void OnListBoxSelectionChanged(object sender, SelectionChangedEventArgs args)
{
if (_viewHandled) return;
if (AssociatedObject.Items.SourceCollection == null) return;
if (AssociatedObject.Items.SourceCollection is null) return;
SelectedItems = AssociatedObject.SelectedItems.Cast<T>().ToArray();
}
@@ -65,7 +65,7 @@ namespace DiscordChatExporter.Gui.Behaviors
private void OnListBoxItemsChanged(object sender, NotifyCollectionChangedEventArgs args)
{
if (_viewHandled) return;
if (AssociatedObject.Items.SourceCollection == null) return;
if (AssociatedObject.Items.SourceCollection is null) return;
SelectItems();
}
@@ -82,7 +82,7 @@ namespace DiscordChatExporter.Gui.Behaviors
{
base.OnDetaching();
if (AssociatedObject != null)
if (AssociatedObject is not null)
{
AssociatedObject.SelectionChanged -= OnListBoxSelectionChanged;
((INotifyCollectionChanged) AssociatedObject.Items).CollectionChanged -= OnListBoxItemsChanged;

View File

@@ -58,7 +58,7 @@ namespace DiscordChatExporter.Gui.Services
if (!_settingsService.IsAutoUpdateEnabled)
return;
if (_updateVersion == null || !_updatePrepared || _updaterLaunched)
if (_updateVersion is null || !_updatePrepared || _updaterLaunched)
return;
try

View File

@@ -19,7 +19,7 @@ namespace DiscordChatExporter.Gui.ViewModels.Dialogs
public IReadOnlyList<Channel>? Channels { get; set; }
public bool IsSingleChannel => Channels == null || Channels.Count == 1;
public bool IsSingleChannel => Channels is null || Channels.Count == 1;
public string? OutputPath { get; set; }
@@ -32,7 +32,7 @@ namespace DiscordChatExporter.Gui.ViewModels.Dialogs
public DateTimeOffset? AfterDate { get; set; }
public bool IsAfterDateSet => AfterDate != null;
public bool IsAfterDateSet => AfterDate is not null;
public TimeSpan? AfterTime { get; set; }
@@ -40,7 +40,7 @@ namespace DiscordChatExporter.Gui.ViewModels.Dialogs
public DateTimeOffset? BeforeDate { get; set; }
public bool IsBeforeDateSet => BeforeDate != null;
public bool IsBeforeDateSet => BeforeDate is not null;
public TimeSpan? BeforeTime { get; set; }
@@ -77,7 +77,7 @@ namespace DiscordChatExporter.Gui.ViewModels.Dialogs
_settingsService.LastShouldDownloadMedia = ShouldDownloadMedia;
// If single channel - prompt file path
if (Channels != null && IsSingleChannel)
if (Channels is not null && IsSingleChannel)
{
var channel = Channels.Single();
var defaultFileName = ExportRequest.GetDefaultOutputFileName(

View File

@@ -44,7 +44,7 @@ namespace DiscordChatExporter.Gui.ViewModels
public Guild? SelectedGuild { get; set; }
public IReadOnlyList<Channel>? AvailableChannels => SelectedGuild != null
public IReadOnlyList<Channel>? AvailableChannels => SelectedGuild is not null
? GuildChannelMap?[SelectedGuild]
: null;
@@ -84,7 +84,7 @@ namespace DiscordChatExporter.Gui.ViewModels
try
{
var updateVersion = await _updateService.CheckForUpdatesAsync();
if (updateVersion == null)
if (updateVersion is null)
return;
Notifications.Enqueue($"Downloading update to {App.Name} v{updateVersion}...");
@@ -111,7 +111,7 @@ namespace DiscordChatExporter.Gui.ViewModels
_settingsService.Load();
if (_settingsService.LastToken != null)
if (_settingsService.LastToken is not null)
{
IsBotToken = _settingsService.LastToken.Type == AuthTokenType.Bot;
TokenValue = _settingsService.LastToken.Value;
@@ -183,12 +183,12 @@ namespace DiscordChatExporter.Gui.ViewModels
}
public bool CanExportChannels =>
!IsBusy && SelectedGuild != null && SelectedChannels != null && SelectedChannels.Any();
!IsBusy && SelectedGuild is not null && SelectedChannels is not null && SelectedChannels.Any();
public async void ExportChannels()
{
var token = _settingsService.LastToken;
if (token == null || SelectedGuild == null || SelectedChannels == null || !SelectedChannels.Any())
if (token is null || SelectedGuild is null || SelectedChannels is null || !SelectedChannels.Any())
return;
var dialog = _viewModelFactory.CreateExportSetupViewModel(SelectedGuild, SelectedChannels);