use new ??= operator

This commit is contained in:
13xforever 2019-10-31 21:31:58 +05:00
parent ec02ce141b
commit 7f829965e4
10 changed files with 13 additions and 13 deletions

View File

@ -245,7 +245,7 @@ namespace AppveyorClient
try
{
mergeDate = mergeDate ?? (DateTime.UtcNow - JobIdSearchThreshold);
mergeDate ??= (DateTime.UtcNow - JobIdSearchThreshold);
result = await FindBuildAsync(
h => h.Builds.Last().Created?.ToUniversalTime() > mergeDate,
b => b.CommitId.StartsWith(commit, StringComparison.InvariantCultureIgnoreCase) && b.Status == "success",

View File

@ -82,7 +82,7 @@ namespace IrdLibraryClient
{
await response.Content.LoadIntoBufferAsync().ConfigureAwait(false);
var result = await response.Content.ReadAsAsync<SearchResult>(underscoreFormatters, cancellationToken).ConfigureAwait(false);
result.Data = result.Data ?? new List<SearchResultItem>(0);
result.Data ??= new List<SearchResultItem>(0);
foreach (var item in result.Data)
{
item.Filename = GetIrdFilename(item.Filename);

View File

@ -181,7 +181,7 @@ namespace PsnClient
{
var loc = locale.AsLocaleData();
var url = new Uri($"https://store.playstation.com/valkyrie-api/{loc.language}/{loc.country}/999/container/{containerId}");
filters = filters ?? new Dictionary<string, string>();
filters ??= new Dictionary<string, string>();
filters["start"] = start.ToString();
filters["size"] = take.ToString();
filters["bucket"] = "games";

View File

@ -33,7 +33,7 @@ namespace CompatBot.EventHandlers
{
if (msg.Author.IsCurrent)
{
previousRepliesBuilder = previousRepliesBuilder ?? new StringBuilder();
previousRepliesBuilder ??= new StringBuilder();
previousRepliesBuilder.AppendLine(msg.Content);
var embeds = msg.Embeds;
if (embeds?.Count > 0)

View File

@ -37,7 +37,7 @@ namespace CompatBot.EventHandlers
{
if (msg.Author.IsCurrent)
{
previousRepliesBuilder = previousRepliesBuilder ?? new StringBuilder();
previousRepliesBuilder ??= new StringBuilder();
previousRepliesBuilder.AppendLine(msg.Content);
var embeds = msg.Embeds;
if (embeds?.Count > 0)

View File

@ -36,7 +36,7 @@ namespace CompatBot.Utils
if (maxLinesPerField < 1)
throw new ArgumentException("Expected a number greater than 0, but was " + maxLinesPerField, nameof(maxLinesPerField));
makeTitle = makeTitle ?? MakeTitle;
makeTitle ??= MakeTitle;
var buffer = new StringBuilder();
var lineCount = 0;

View File

@ -36,8 +36,8 @@ namespace CompatBot.Utils
if (string.IsNullOrEmpty(message))
return;
blockEnd = blockEnd ?? "";
blockStart = blockStart ?? "";
blockEnd ??= "";
blockStart ??= "";
var maxContentSize = blockSize - blockEnd.Length - blockStart.Length;
await channel.TriggerTypingAsync().ConfigureAwait(false);
var buffer = new StringBuilder();

View File

@ -70,7 +70,7 @@ namespace CompatBot.Utils
{
try
{
showBoth = showBoth ?? message.Channel.IsPrivate;
showBoth ??= message.Channel.IsPrivate;
var canReact = message.Channel.IsPrivate || message.Channel.PermissionsFor(message.Channel.Guild.CurrentMember).HasPermission(Permissions.AddReactions);
if (canReact)
await message.CreateReactionAsync(emoji).ConfigureAwait(false);

View File

@ -101,7 +101,7 @@ namespace CompatBot.Utils
public static string AsString(this ReadOnlySequence<byte> buffer, Encoding encoding = null)
{
encoding = encoding ?? Latin8BitEncoding;
encoding ??= Latin8BitEncoding;
if (buffer.IsSingleSegment)
return encoding.GetString(buffer.First.Span);
@ -186,7 +186,7 @@ namespace CompatBot.Utils
public static string PadLeftVisible(this string s, int totalWidth, char padding = ' ')
{
s = s ?? "";
s ??= "";
var valueWidth = s.GetVisibleLength();
var diff = s.Length - valueWidth;
totalWidth += diff;
@ -195,7 +195,7 @@ namespace CompatBot.Utils
public static string PadRightVisible(this string s, int totalWidth, char padding = ' ')
{
s = s ?? "";
s ??= "";
var valueWidth = s.GetVisibleLength();
var diff = s.Length - valueWidth;
totalWidth += diff;

View File

@ -62,7 +62,7 @@ namespace CompatBot.Utils.ResultFormatters
}
}
}
builder = builder ?? new DiscordEmbedBuilder {Title = prDesc, Url = url, Description = desc, Color = Config.Colors.DownloadLinks};
builder ??= new DiscordEmbedBuilder {Title = prDesc, Url = url, Description = desc, Color = Config.Colors.DownloadLinks};
var currentCommit = currentPrInfo?.MergeCommitSha;
var latestCommit = latestPrInfo?.MergeCommitSha;
var currentAppveyorBuild = await appveyorClient.GetMasterBuildAsync(currentCommit, currentPrInfo?.MergedAt, Config.Cts.Token).ConfigureAwait(false);