dev: Using collection expressions, no functional change

This commit is contained in:
Kwoth
2024-05-13 14:54:24 +00:00
parent 52438f45e1
commit 9406a9cc34
38 changed files with 173 additions and 142 deletions

View File

@@ -6,10 +6,13 @@ namespace NadekoBot.Extensions;
public static class StringExtensions
{
private static readonly HashSet<char> _lettersAndDigits = new(Enumerable.Range(48, 10)
.Concat(Enumerable.Range(65, 26))
.Concat(Enumerable.Range(97, 26))
.Select(x => (char)x));
private static readonly HashSet<char> _lettersAndDigits =
[
..Enumerable.Range(48, 10)
.Concat(Enumerable.Range(65, 26))
.Concat(Enumerable.Range(97, 26))
.Select(x => (char)x)
];
private static readonly Regex _filterRegex = new(@"discord(?:\.gg|\.io|\.me|\.li|(?:app)?\.com\/invite)\/(\w+)",
RegexOptions.Compiled | RegexOptions.IgnoreCase);
@@ -43,7 +46,7 @@ public static class StringExtensions
public static string ToTitleCase(this string str)
{
var tokens = str.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
var tokens = str.Split([" "], StringSplitOptions.RemoveEmptyEntries);
for (var i = 0; i < tokens.Length; i++)
{
var token = tokens[i];

View File

@@ -146,14 +146,14 @@ public sealed partial class BotConfig : ICloneable<BotConfig>
Prefix = ".";
RotateStatuses = false;
GroupGreets = false;
DmHelpTextKeywords = new()
{
DmHelpTextKeywords =
[
"help",
"commands",
"cmds",
"module",
"can you do"
};
];
}
// [Comment(@"Whether the prefix will be a suffix, or prefix.
@@ -178,8 +178,8 @@ public sealed partial class BlockedConfig
public BlockedConfig()
{
Modules = new();
Commands = new();
Modules = [];
Commands = [];
}
}

View File

@@ -259,10 +259,10 @@ public class Deck
}
private readonly string[] _regIndicators =
{
[
"🇦", ":two:", ":three:", ":four:", ":five:", ":six:", ":seven:", ":eight:", ":nine:", ":keycap_ten:",
"🇯", "🇶", "🇰"
};
];
public Card(CardSuit s, int cardNum)
{

View File

@@ -64,7 +64,7 @@ public sealed class MedusaNinjectIocModule : IIocModule, IDisposable
var assembly = typeof(JsonSerializerOptions).Assembly;
var updateHandlerType = assembly.GetType("System.Text.Json.JsonSerializerOptionsUpdateHandler");
var clearCacheMethod = updateHandlerType?.GetMethod("ClearCache", BindingFlags.Static | BindingFlags.Public);
clearCacheMethod?.Invoke(null, new object?[] { null });
clearCacheMethod?.Invoke(null, [null]);
isLoaded = false;
}

View File

@@ -140,7 +140,7 @@ public sealed class MedusaLoaderService : IMedusaLoaderService, IReadyExecutor,
=> alias.Equals(commandName, StringComparison.InvariantCultureIgnoreCase)))
?.OptionalStrings
.Args
?? new[] { string.Empty };
?? [string.Empty];
}
public Task ReloadStrings()
@@ -375,7 +375,7 @@ public sealed class MedusaLoaderService : IMedusaLoaderService, IReadyExecutor,
var targetType = parserType.BaseType!.GetGenericArguments()[0];
var typeReaderInstance = (TypeReader)Activator.CreateInstance(
typeof(ParamParserAdapter<>).MakeGenericType(targetType),
args: new[] { parserObj, strings, _cont })!;
args: [parserObj, strings, _cont])!;
typeReaders.Add(targetType, typeReaderInstance);
}
@@ -888,7 +888,7 @@ public sealed class MedusaLoaderService : IMedusaLoaderService, IReadyExecutor,
var cmdAttribute = method.GetCustomAttribute<cmdAttribute>(true)!;
var aliases = cmdAttribute.Aliases;
if (aliases.Length == 0)
aliases = new[] { method.Name.ToLowerInvariant() };
aliases = [method.Name.ToLowerInvariant()];
cmds.Add(new(
aliases,

View File

@@ -81,7 +81,7 @@ public class BotStrings : IBotStrings
return new CommandStrings()
{
Examples = new[] { "" },
Examples = [""],
Desc = "?",
Params = []
};

View File

@@ -19,7 +19,7 @@ public class MultilineScalarFlowStyleEmitter : ChainedEventEmitter
var value = eventInfo.Source.Value as string;
if (!string.IsNullOrEmpty(value))
{
var isMultiLine = value.IndexOfAny(new[] { '\r', '\n', '\x85', '\x2028', '\x2029' }) >= 0;
var isMultiLine = value.IndexOfAny(['\r', '\n', '\x85', '\x2028', '\x2029']) >= 0;
if (isMultiLine)
{
eventInfo = new(eventInfo.Source)