Using pattern matching for nulls where applicable, discarded unused lambda parameters, cleaned up some classes. Unignored ServerLog commands which was mistakenly ignored due to a .gitignore rule

This commit is contained in:
Kwoth
2022-01-01 08:44:51 +01:00
parent f81f9fadd3
commit 9b4eb21321
91 changed files with 1591 additions and 224 deletions

View File

@@ -342,7 +342,7 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
// The Volatile.Read ensures that the load of the fields of 'n' doesn't move before the load from buckets[i].
var current = Volatile.Read(ref tables.Buckets[bucketNo]);
while (current != null)
while (current is not null)
{
if (hashcode == current.Hashcode && _comparer.Equals(current.Item, item))
return true;
@@ -410,7 +410,7 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
// The Volatile.Read ensures that the load of the fields of 'current' doesn't move before the load from buckets[i].
var current = Volatile.Read(ref buckets[i]);
while (current != null)
while (current is not null)
{
yield return current.Item;
current = current.Next;
@@ -454,7 +454,7 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
if (tables != _tables) continue;
Node previous = null;
for (var current = tables.Buckets[bucketNo]; current != null; current = current.Next)
for (var current = tables.Buckets[bucketNo]; current is not null; current = current.Next)
{
Debug.Assert((previous is null && current == tables.Buckets[bucketNo]) || previous.Next == current);
@@ -504,7 +504,7 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
// Try to find this item in the bucket
Node previous = null;
for (var current = tables.Buckets[bucketNo]; current != null; current = current.Next)
for (var current = tables.Buckets[bucketNo]; current is not null; current = current.Next)
{
Debug.Assert((previous is null && current == tables.Buckets[bucketNo]) || previous.Next == current);
if (hashcode == current.Hashcode && _comparer.Equals(current.Item, item))
@@ -656,7 +656,7 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
for (var i = 0; i < tables.Buckets.Length; i++)
{
var current = tables.Buckets[i];
while (current != null)
while (current is not null)
{
var next = current.Next;
GetBucketAndLockNo(current.Hashcode,
@@ -741,7 +741,7 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
{
var buckets = _tables.Buckets;
for (var i = 0; i < buckets.Length; i++)
for (var current = buckets[i]; current != null; current = current.Next)
for (var current = buckets[i]; current is not null; current = current.Next)
{
array[index] = current.Item;
index++; //this should never flow, CopyToItems is only called when there's no overflow risk

View File

@@ -17,7 +17,7 @@ public static class OptionsParser
x.HelpWriter = null;
});
var res = p.ParseArguments<T>(args);
options = res.MapResult(x => x, x => options);
options = res.MapResult(x => x, _ => options);
options.NormalizeOptions();
return (options, res.Tag == ParserResultType.Parsed);
}

View File

@@ -62,7 +62,7 @@ public class ReplacementBuilder
() =>
{
var to = TimeZoneInfo.Local;
if (g != null)
if (g is not null)
if (GuildTimezoneService.AllServices.TryGetValue(client.CurrentUser.Id, out var tz))
to = tz.GetTimeZoneOrDefault(g.Id) ?? TimeZoneInfo.Local;

View File

@@ -50,13 +50,13 @@ public class Replacer
Image = Replace(embedData.Image),
Url = Replace(embedData.Url)
};
if (embedData.Author != null)
if (embedData.Author is not null)
newEmbedData.Author = new()
{
Name = Replace(embedData.Author.Name), IconUrl = Replace(embedData.Author.IconUrl)
};
if (embedData.Fields != null)
if (embedData.Fields is not null)
{
var fields = new List<SmartTextEmbedField>();
foreach (var f in embedData.Fields)
@@ -71,7 +71,7 @@ public class Replacer
newEmbedData.Fields = fields.ToArray();
}
if (embedData.Footer != null)
if (embedData.Footer is not null)
newEmbedData.Footer = new()
{
Text = Replace(embedData.Footer.Text), IconUrl = Replace(embedData.Footer.IconUrl)

View File

@@ -22,7 +22,7 @@ public sealed record SmartEmbedText : SmartText
|| !string.IsNullOrWhiteSpace(Url)
|| !string.IsNullOrWhiteSpace(Thumbnail)
|| !string.IsNullOrWhiteSpace(Image)
|| (Footer != null
|| (Footer is not null
&& (!string.IsNullOrWhiteSpace(Footer.Text) || !string.IsNullOrWhiteSpace(Footer.IconUrl)))
|| Fields is { Length: > 0 };
@@ -62,10 +62,10 @@ public sealed record SmartEmbedText : SmartText
if (!string.IsNullOrWhiteSpace(Description))
embed.WithDescription(Description);
if (Url != null && Uri.IsWellFormedUriString(Url, UriKind.Absolute))
if (Url is not null && Uri.IsWellFormedUriString(Url, UriKind.Absolute))
embed.WithUrl(Url);
if (Footer != null)
if (Footer is not null)
embed.WithFooter(efb =>
{
efb.WithText(Footer.Text);
@@ -73,13 +73,13 @@ public sealed record SmartEmbedText : SmartText
efb.WithIconUrl(Footer.IconUrl);
});
if (Thumbnail != null && Uri.IsWellFormedUriString(Thumbnail, UriKind.Absolute))
if (Thumbnail is not null && Uri.IsWellFormedUriString(Thumbnail, UriKind.Absolute))
embed.WithThumbnailUrl(Thumbnail);
if (Image != null && Uri.IsWellFormedUriString(Image, UriKind.Absolute))
if (Image is not null && Uri.IsWellFormedUriString(Image, UriKind.Absolute))
embed.WithImageUrl(Image);
if (Author != null && !string.IsNullOrWhiteSpace(Author.Name))
if (Author is not null && !string.IsNullOrWhiteSpace(Author.Name))
{
if (!Uri.IsWellFormedUriString(Author.IconUrl, UriKind.Absolute))
Author.IconUrl = null;
@@ -89,7 +89,7 @@ public sealed record SmartEmbedText : SmartText
embed.WithAuthor(Author.Name, Author.IconUrl, Author.Url);
}
if (Fields != null)
if (Fields is not null)
foreach (var f in Fields)
if (!string.IsNullOrWhiteSpace(f.Name) && !string.IsNullOrWhiteSpace(f.Value))
embed.AddField(f.Name, f.Value, f.Inline);

View File

@@ -16,7 +16,7 @@ public sealed class GuildTypeReader : NadekoTypeReader<IGuild>
?? //by id
guilds.FirstOrDefault(g => g.Name.Trim().ToUpperInvariant() == input); //by name
if (guild != null)
if (guild is not null)
return Task.FromResult(TypeReaderResult.FromSuccess(guild));
return Task.FromResult(

View File

@@ -57,7 +57,7 @@ public class CommentGatheringTypeInspector : TypeInspectorSkeleton
public IObjectDescriptor Read(object target)
{
var comment = baseDescriptor.GetCustomAttribute<CommentAttribute>();
return comment != null
return comment is not null
? new CommentsObjectDescriptor(baseDescriptor.Read(target), comment.Comment)
: baseDescriptor.Read(target);
}