Use `is null`/`is not null`

pull/497/head
Tyrrrz 4 years ago
parent ebe4d58a42
commit 3aef7faa1e

@ -194,7 +194,7 @@ namespace DiscordChatExporter.Core.Discord
var parentId = response.GetPropertyOrNull("parent_id")?.GetString().Pipe(Snowflake.Parse);
var category = parentId != null
var category = parentId is not null
? await GetChannelCategoryAsync(parentId.Value)
: null;
@ -224,7 +224,7 @@ namespace DiscordChatExporter.Core.Discord
// will not appear in the output.
// Additionally, it provides the date of the last message, which is used to calculate progress.
var lastMessage = await TryGetLastMessageAsync(channelId, before);
if (lastMessage == null || lastMessage.Timestamp < after?.ToDate())
if (lastMessage is null || lastMessage.Timestamp < after?.ToDate())
yield break;
// Keep track of first message in range in order to calculate progress

@ -57,7 +57,7 @@ namespace DiscordChatExporter.Core.Exporting
var roles = member?.RoleIds.Join(Roles, i => i, r => r.Id, (_, role) => role);
return roles?
.Where(r => r.Color != null)
.Where(r => r.Color is not null)
.OrderByDescending(r => r.Position)
.Select(r => r.Color)
.FirstOrDefault();

@ -127,17 +127,17 @@ namespace DiscordChatExporter.Core.Exporting
buffer.Append($"{guild.Name} - {channel.Category.Name} - {channel.Name} [{channel.Id}]");
// Date range
if (after != null || before != null)
if (after is not null || before is not null)
{
buffer.Append(" (");
// Both 'after' and 'before' are set
if (after != null && before != null)
if (after is not null && before is not null)
{
buffer.Append($"{after?.ToDate():yyyy-MM-dd} to {before?.ToDate():yyyy-MM-dd}");
}
// Only 'after' is set
else if (after != null)
else if (after is not null)
{
buffer.Append($"after {after?.ToDate():yyyy-MM-dd}");
}

@ -62,7 +62,7 @@ namespace DiscordChatExporter.Core.Exporting
: (DateTimeOffset?) null
);
if (lastModified != null)
if (lastModified is not null)
{
File.SetCreationTimeUtc(filePath, lastModified.Value.UtcDateTime);
File.SetLastWriteTimeUtc(filePath, lastModified.Value.UtcDateTime);

@ -21,13 +21,13 @@ namespace DiscordChatExporter.Core.Exporting
private bool IsPartitionLimitReached() =>
_messageCount > 0 &&
_context.Request.PartitionLimit != null &&
_context.Request.PartitionLimit is not null &&
_context.Request.PartitionLimit != 0 &&
_messageCount % _context.Request.PartitionLimit == 0;
private async ValueTask ResetWriterAsync()
{
if (_writer != null)
if (_writer is not null)
{
await _writer.WritePostambleAsync();
await _writer.DisposeAsync();
@ -45,7 +45,7 @@ namespace DiscordChatExporter.Core.Exporting
}
// Writer is still valid - return
if (_writer != null)
if (_writer is not null)
return _writer;
var filePath = GetPartitionFilePath(_context.Request.OutputBaseFilePath, _partitionIndex);

@ -17,7 +17,7 @@
var userColor = Model.ExportContext.TryGetUserColor(Model.MessageGroup.Author.Id);
var userColorStyle = userColor != null
var userColorStyle = userColor is not null
? $"color: rgb({userColor?.R},{userColor?.G},{userColor?.B})"
: null;
@ -25,19 +25,19 @@
? Model.MessageGroup.Author.Name
: userMember?.Nick ?? Model.MessageGroup.Author.Name;
var referencedUserMember = Model.MessageGroup.ReferencedMessage != null
var referencedUserMember = Model.MessageGroup.ReferencedMessage is not null
? Model.ExportContext.TryGetMember(Model.MessageGroup.ReferencedMessage.Author.Id)
: null;
var referencedUserColor = Model.MessageGroup.ReferencedMessage != null
var referencedUserColor = Model.MessageGroup.ReferencedMessage is not null
? Model.ExportContext.TryGetUserColor(Model.MessageGroup.ReferencedMessage.Author.Id)
: null;
var referencedUserColorStyle = referencedUserColor != null
var referencedUserColorStyle = referencedUserColor is not null
? $"color: rgb({referencedUserColor?.R},{referencedUserColor?.G},{referencedUserColor?.B})"
: null;
var referencedUserNick = Model.MessageGroup.ReferencedMessage != null
var referencedUserNick = Model.MessageGroup.ReferencedMessage is not null
? Model.MessageGroup.ReferencedMessage.Author.IsBot
? Model.MessageGroup.ReferencedMessage.Author.Name
: referencedUserMember?.Nick ?? Model.MessageGroup.ReferencedMessage.Author.Name
@ -45,12 +45,12 @@
}
<div class="chatlog__message-group">
@if (Model.MessageGroup.Reference != null)
@if (Model.MessageGroup.Reference is not null)
{
<div class="chatlog__reference-symbol">
</div>
<div class="chatlog__reference">
@if (Model.MessageGroup.ReferencedMessage != null)
@if (Model.MessageGroup.ReferencedMessage is not null)
{
<img class="chatlog__reference-avatar" src="@await ResolveUrlAsync(Model.MessageGroup.ReferencedMessage.Author.AvatarUrl)" alt="Avatar">
<span class="chatlog__reference-name" title="@Model.MessageGroup.ReferencedMessage.Author.FullName" style="@referencedUserColorStyle">@referencedUserNick</span>
@ -66,7 +66,7 @@
}
</span>
@if (Model.MessageGroup.ReferencedMessage.EditedTimestamp != null)
@if (Model.MessageGroup.ReferencedMessage.EditedTimestamp is not null)
{
<span class="chatlog__reference-edited-timestamp" title="@FormatDate(Model.MessageGroup.ReferencedMessage.EditedTimestamp.Value)">(edited)</span>
}
@ -98,13 +98,13 @@
var isPinnedStyle = message.IsPinned ? "chatlog__message--pinned" : null;
<div class="chatlog__message @isPinnedStyle" data-message-id="@message.Id" id="message-@message.Id">
@if (!string.IsNullOrWhiteSpace(message.Content) || message.EditedTimestamp != null)
@if (!string.IsNullOrWhiteSpace(message.Content) || message.EditedTimestamp is not null)
{
<div class="chatlog__content">
<div class="markdown">
<span class="preserve-whitespace">@Raw(FormatMarkdown(message.Content))</span>
@if (message.EditedTimestamp != null)
@if (message.EditedTimestamp is not null)
{
<span class="chatlog__edited-timestamp" title="@FormatDate(message.EditedTimestamp.Value)">(edited)</span>
}
@ -162,7 +162,7 @@
@foreach (var embed in message.Embeds)
{
<div class="chatlog__embed">
@if (embed.Color != null)
@if (embed.Color is not null)
{
var embedColorStyle = $"background-color: rgba({embed.Color?.R},{embed.Color?.G},{embed.Color?.B},{embed.Color?.A})";
<div class="chatlog__embed-color-pill" style="@embedColorStyle"></div>
@ -175,7 +175,7 @@
<div class="chatlog__embed-content-container">
<div class="chatlog__embed-content">
<div class="chatlog__embed-text">
@if (embed.Author != null)
@if (embed.Author is not null)
{
<div class="chatlog__embed-author">
@if (!string.IsNullOrWhiteSpace(embed.Author.IconUrl))
@ -249,7 +249,7 @@
}
</div>
@if (embed.Thumbnail != null)
@if (embed.Thumbnail is not null)
{
<div class="chatlog__embed-thumbnail-container">
<a class="chatlog__embed-thumbnail-link" href="@await ResolveUrlAsync(embed.Thumbnail.Url)">
@ -259,7 +259,7 @@
}
</div>
@if (embed.Image != null)
@if (embed.Image is not null)
{
<div class="chatlog__embed-image-container">
<a class="chatlog__embed-image-link" href="@await ResolveUrlAsync(embed.Image.Url)">
@ -268,7 +268,7 @@
</div>
}
@if (embed.Footer != null || embed.Timestamp != null)
@if (embed.Footer is not null || embed.Timestamp is not null)
{
<div class="chatlog__embed-footer">
@if (!string.IsNullOrWhiteSpace(embed.Footer?.IconUrl))
@ -282,12 +282,12 @@
@embed.Footer.Text
}
@if (!string.IsNullOrWhiteSpace(embed.Footer?.Text) && embed.Timestamp != null)
@if (!string.IsNullOrWhiteSpace(embed.Footer?.Text) && embed.Timestamp is not null)
{
@(" • ")
}
@if (embed.Timestamp != null)
@if (embed.Timestamp is not null)
{
@FormatDate(embed.Timestamp.Value)
}

@ -78,18 +78,18 @@
<div class="preamble__entry preamble__entry--small">@Model.ExportContext.Request.Channel.Topic</div>
}
@if (Model.ExportContext.Request.After != null || Model.ExportContext.Request.Before != null)
@if (Model.ExportContext.Request.After is not null || Model.ExportContext.Request.Before is not null)
{
<div class="preamble__entry preamble__entry--small">
@if (Model.ExportContext.Request.After != null && Model.ExportContext.Request.Before != null)
@if (Model.ExportContext.Request.After is not null && Model.ExportContext.Request.Before is not null)
{
@($"Between {FormatDate(Model.ExportContext.Request.After.Value.ToDate())} and {FormatDate(Model.ExportContext.Request.Before.Value.ToDate())}")
}
else if (Model.ExportContext.Request.After != null)
else if (Model.ExportContext.Request.After is not null)
{
@($"After {FormatDate(Model.ExportContext.Request.After.Value.ToDate())}")
}
else if (Model.ExportContext.Request.Before != null)
else if (Model.ExportContext.Request.Before is not null)
{
@($"Before {FormatDate(Model.ExportContext.Request.Before.Value.ToDate())}")
}

@ -118,19 +118,19 @@ namespace DiscordChatExporter.Core.Exporting.Writers
_writer.WriteString("timestamp", embed.Timestamp);
_writer.WriteString("description", FormatMarkdown(embed.Description));
if (embed.Color != null)
if (embed.Color is not null)
_writer.WriteString("color", embed.Color.Value.ToHex());
if (embed.Author != null)
if (embed.Author is not null)
await WriteEmbedAuthorAsync(embed.Author);
if (embed.Thumbnail != null)
if (embed.Thumbnail is not null)
await WriteEmbedThumbnailAsync(embed.Thumbnail);
if (embed.Image != null)
if (embed.Image is not null)
await WriteEmbedImageAsync(embed.Image);
if (embed.Footer != null)
if (embed.Footer is not null)
await WriteEmbedFooterAsync(embed.Footer);
// Fields
@ -266,7 +266,7 @@ namespace DiscordChatExporter.Core.Exporting.Writers
_writer.WriteEndArray();
// Message reference
if (message.Reference != null)
if (message.Reference is not null)
{
_writer.WriteStartObject("reference");
_writer.WriteString("messageId", message.Reference.MessageId?.ToString());

@ -112,7 +112,7 @@ namespace DiscordChatExporter.Core.Exporting.Writers.MarkdownVisitors
var name = role?.Name ?? "deleted-role";
var color = role?.Color;
var style = color != null
var style = color is not null
? $"color: rgb({color?.R}, {color?.G}, {color?.B}); background-color: rgba({color?.R}, {color?.G}, {color?.B}, 0.1);"
: "";

@ -118,10 +118,10 @@ namespace DiscordChatExporter.Core.Exporting.Writers
if (!string.IsNullOrWhiteSpace(Context.Request.Channel.Topic))
await _writer.WriteLineAsync($"Topic: {Context.Request.Channel.Topic}");
if (Context.Request.After != null)
if (Context.Request.After is not null)
await _writer.WriteLineAsync($"After: {Context.FormatDate(Context.Request.After.Value.ToDate())}");
if (Context.Request.Before != null)
if (Context.Request.Before is not null)
await _writer.WriteLineAsync($"Before: {Context.FormatDate(Context.Request.Before.Value.ToDate())}");
await _writer.WriteLineAsync('='.Repeat(62));

@ -27,11 +27,11 @@ namespace DiscordChatExporter.Core.Markdown.Matching
var match = matcher.TryMatch(stringPart);
// If there's no match - continue
if (match == null)
if (match is null)
continue;
// If this match is earlier than previous earliest - replace
if (earliestMatch == null || match.StringPart.StartIndex < earliestMatch.StringPart.StartIndex)
if (earliestMatch is null || match.StringPart.StartIndex < earliestMatch.StringPart.StartIndex)
earliestMatch = match;
// If the earliest match starts at the very beginning - break,

@ -21,7 +21,7 @@ namespace DiscordChatExporter.Core.Markdown.Matching
var match = matcher.TryMatch(stringPart.Slice(currentIndex, stringPart.EndIndex - currentIndex));
// If there's no match - break
if (match == null)
if (match is null)
break;
// If this match doesn't start immediately at current index - transform and yield fallback first

@ -32,7 +32,7 @@ namespace DiscordChatExporter.Core.Utils
if (i > 3)
{
var retryAfterDelay = result.Result.Headers.RetryAfter.Delta;
if (retryAfterDelay != null)
if (retryAfterDelay is not null)
return retryAfterDelay.Value + TimeSpan.FromSeconds(1); // margin just in case
}
}

@ -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;

@ -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

@ -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(

@ -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);

Loading…
Cancel
Save