From 70a1c9db8ca6612a9dfd09c9e2cc34369a55f1cf Mon Sep 17 00:00:00 2001 From: Alexey Golub Date: Mon, 23 Mar 2020 19:11:15 +0200 Subject: [PATCH] Clean up warnings --- .../DiscordChatExporter.Gui.csproj | 2 +- .../ViewModels/Components/ChannelViewModel.cs | 4 ++-- .../ViewModels/Components/GuildViewModel.cs | 6 +++--- .../ViewModels/Dialogs/ExportSetupViewModel.cs | 8 ++++---- .../ViewModels/Framework/DialogScreen.cs | 3 ++- DiscordChatExporter.Gui/ViewModels/RootViewModel.cs | 12 ++++++------ 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/DiscordChatExporter.Gui/DiscordChatExporter.Gui.csproj b/DiscordChatExporter.Gui/DiscordChatExporter.Gui.csproj index b7933d4..90bf5af 100644 --- a/DiscordChatExporter.Gui/DiscordChatExporter.Gui.csproj +++ b/DiscordChatExporter.Gui/DiscordChatExporter.Gui.csproj @@ -32,7 +32,7 @@ - + \ No newline at end of file diff --git a/DiscordChatExporter.Gui/ViewModels/Components/ChannelViewModel.cs b/DiscordChatExporter.Gui/ViewModels/Components/ChannelViewModel.cs index b6d2f81..73e402b 100644 --- a/DiscordChatExporter.Gui/ViewModels/Components/ChannelViewModel.cs +++ b/DiscordChatExporter.Gui/ViewModels/Components/ChannelViewModel.cs @@ -5,13 +5,13 @@ namespace DiscordChatExporter.Gui.ViewModels.Components { public partial class ChannelViewModel : PropertyChangedBase { - public Channel Model { get; set; } + public Channel? Model { get; set; } public string? Category { get; set; } } public partial class ChannelViewModel { - public static implicit operator Channel(ChannelViewModel viewModel) => viewModel.Model; + public static implicit operator Channel?(ChannelViewModel? viewModel) => viewModel?.Model; } } \ No newline at end of file diff --git a/DiscordChatExporter.Gui/ViewModels/Components/GuildViewModel.cs b/DiscordChatExporter.Gui/ViewModels/Components/GuildViewModel.cs index f5c0448..71344f6 100644 --- a/DiscordChatExporter.Gui/ViewModels/Components/GuildViewModel.cs +++ b/DiscordChatExporter.Gui/ViewModels/Components/GuildViewModel.cs @@ -6,13 +6,13 @@ namespace DiscordChatExporter.Gui.ViewModels.Components { public partial class GuildViewModel : PropertyChangedBase { - public Guild Model { get; set; } + public Guild? Model { get; set; } - public IReadOnlyList Channels { get; set; } + public IReadOnlyList? Channels { get; set; } } public partial class GuildViewModel { - public static implicit operator Guild(GuildViewModel viewModel) => viewModel.Model; + public static implicit operator Guild?(GuildViewModel? viewModel) => viewModel?.Model; } } \ No newline at end of file diff --git a/DiscordChatExporter.Gui/ViewModels/Dialogs/ExportSetupViewModel.cs b/DiscordChatExporter.Gui/ViewModels/Dialogs/ExportSetupViewModel.cs index d1292c0..46148f4 100644 --- a/DiscordChatExporter.Gui/ViewModels/Dialogs/ExportSetupViewModel.cs +++ b/DiscordChatExporter.Gui/ViewModels/Dialogs/ExportSetupViewModel.cs @@ -14,11 +14,11 @@ namespace DiscordChatExporter.Gui.ViewModels.Dialogs private readonly DialogManager _dialogManager; private readonly SettingsService _settingsService; - public GuildViewModel Guild { get; set; } + public GuildViewModel? Guild { get; set; } - public IReadOnlyList Channels { get; set; } + public IReadOnlyList? Channels { get; set; } - public bool IsSingleChannel => Channels.Count == 1; + public bool IsSingleChannel => Channels == null || Channels.Count == 1; public string? OutputPath { get; set; } @@ -62,7 +62,7 @@ namespace DiscordChatExporter.Gui.ViewModels.Dialogs var channel = Channels.Single(); // Generate default file name - var defaultFileName = ExportLogic.GetDefaultExportFileName(SelectedFormat, Guild, channel, After, Before); + var defaultFileName = ExportLogic.GetDefaultExportFileName(SelectedFormat, Guild!, channel!, After, Before); // Generate filter var ext = SelectedFormat.GetFileExtension(); diff --git a/DiscordChatExporter.Gui/ViewModels/Framework/DialogScreen.cs b/DiscordChatExporter.Gui/ViewModels/Framework/DialogScreen.cs index e5a535c..91b6e1c 100644 --- a/DiscordChatExporter.Gui/ViewModels/Framework/DialogScreen.cs +++ b/DiscordChatExporter.Gui/ViewModels/Framework/DialogScreen.cs @@ -5,7 +5,8 @@ namespace DiscordChatExporter.Gui.ViewModels.Framework { public abstract class DialogScreen : PropertyChangedBase { - public T DialogResult { get; private set; } + // ReSharper disable once RedundantDefaultMemberInitializer + public T DialogResult { get; private set; } = default!; public event EventHandler? Closed; diff --git a/DiscordChatExporter.Gui/ViewModels/RootViewModel.cs b/DiscordChatExporter.Gui/ViewModels/RootViewModel.cs index 6c8ad64..f95e4fe 100644 --- a/DiscordChatExporter.Gui/ViewModels/RootViewModel.cs +++ b/DiscordChatExporter.Gui/ViewModels/RootViewModel.cs @@ -178,7 +178,7 @@ namespace DiscordChatExporter.Gui.ViewModels // Create guild view model var guildViewModel = _viewModelFactory.CreateGuildViewModel(guild, channelViewModels.OrderBy(c => c.Category) - .ThenBy(c => c.Model.Name) + .ThenBy(c => c.Model!.Name) .ToArray()); // Add to list @@ -210,7 +210,7 @@ namespace DiscordChatExporter.Gui.ViewModels // Create guild view model var guildViewModel = _viewModelFactory.CreateGuildViewModel(guild, channelViewModels.OrderBy(c => c.Category) - .ThenBy(c => c.Model.Name) + .ThenBy(c => c.Model!.Name) .ToArray()); // Add to list @@ -256,7 +256,7 @@ namespace DiscordChatExporter.Gui.ViewModels return; // Create a progress operation for each channel to export - var operations = ProgressManager.CreateOperations(dialog.Channels.Count); + var operations = ProgressManager.CreateOperations(dialog.Channels!.Count); // Export channels var successfulExportCount = 0; @@ -267,7 +267,7 @@ namespace DiscordChatExporter.Gui.ViewModels try { - await _exportService.ExportChatLogAsync(token, dialog.Guild, channel, + await _exportService.ExportChatLogAsync(token, dialog.Guild!, channel!, dialog.OutputPath!, dialog.SelectedFormat, dialog.PartitionLimit, dialog.After, dialog.Before, operation); @@ -275,11 +275,11 @@ namespace DiscordChatExporter.Gui.ViewModels } catch (HttpErrorStatusCodeException ex) when (ex.StatusCode == HttpStatusCode.Forbidden) { - Notifications.Enqueue($"You don't have access to channel [{channel.Model.Name}]"); + Notifications.Enqueue($"You don't have access to channel [{channel.Model!.Name}]"); } catch (HttpErrorStatusCodeException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { - Notifications.Enqueue($"Channel [{channel.Model.Name}] doesn't exist"); + Notifications.Enqueue($"Channel [{channel.Model!.Name}] doesn't exist"); } catch (DomainException ex) {