use collection expressions

This commit is contained in:
2026-05-11 15:17:00 +02:00
parent 478d536b7a
commit d369234ab9
26 changed files with 53 additions and 53 deletions
@@ -92,7 +92,7 @@ public static class RavenQueryableExtensions
searchTerms = searchTerms.Trim(); searchTerms = searchTerms.Trim();
string[] searchParts = searchTerms.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => string[] searchParts = searchTerms.Split([" "], StringSplitOptions.RemoveEmptyEntries).Select(x =>
{ {
if (suffix != null) if (suffix != null)
{ {
@@ -107,7 +107,7 @@ public static class RavenQueryableExtensions
if (searchTerms.StartsWith('"') && searchTerms.EndsWith('"')) if (searchTerms.StartsWith('"') && searchTerms.EndsWith('"'))
{ {
searchParts = new[] { searchTerms }; searchParts = [searchTerms];
} }
return source.Search(fieldSelector, searchParts, @operator: @operator); return source.Search(fieldSelector, searchParts, @operator: @operator);
@@ -4,7 +4,7 @@ namespace Mixtape.Raven;
public class MixtapeTreeHierarchyIndexResult : MixtapeIdEntity, ISupportsDbConventions public class MixtapeTreeHierarchyIndexResult : MixtapeIdEntity, ISupportsDbConventions
{ {
public List<string> Path { get; set; } = new List<string>(); public List<string> Path { get; set; } = [];
} }
public abstract class MixtapeTreeHierarchyIndex<T> : MixtapeIndex<T, MixtapeTreeHierarchyIndexResult> where T : MixtapeIdEntity, ISupportsTrees public abstract class MixtapeTreeHierarchyIndex<T> : MixtapeIndex<T, MixtapeTreeHierarchyIndexResult> where T : MixtapeIdEntity, ISupportsTrees
+1 -1
View File
@@ -50,7 +50,7 @@ internal class MixtapeRavenModule : MixtapeModule
IDocumentStore store = new DocumentStore() IDocumentStore store = new DocumentStore()
{ {
Database = ravenOptions.Database, Database = ravenOptions.Database,
Urls = new string[1] { ravenOptions.Url }, Urls = [ravenOptions.Url],
Conventions = Conventions =
{ {
AggressiveCache = AggressiveCache =
@@ -46,7 +46,7 @@ public partial class RavenOperations : IRavenOperations
ids = ids.Distinct().ToArray(); ids = ids.Distinct().ToArray();
Dictionary<string, T> models = await Session.LoadAsync<T>(ids); Dictionary<string, T> models = await Session.LoadAsync<T>(ids);
List<T> result = new(); List<T> result = [];
foreach (string id in ids) foreach (string id in ids)
{ {
@@ -148,7 +148,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc /> /// <inheritdoc />
public virtual async Task<List<T>> LoadAll<T>() where T : MixtapeIdEntity, new() public virtual async Task<List<T>> LoadAll<T>() where T : MixtapeIdEntity, new()
{ {
List<T> items = new(); List<T> items = [];
await foreach (T item in Stream<T>(null)) await foreach (T item in Stream<T>(null))
{ {
@@ -25,10 +25,10 @@ public partial class RavenOperations : IRavenOperations
if (result == null) if (result == null)
{ {
return Array.Empty<T>(); return [];
} }
List<string> ids = result.Path ?? new(); List<string> ids = result.Path ?? [];
ids.Add(id); ids.Add(id);
return (await Session.LoadAsync<T>(ids)).Select(x => x.Value).ToArray(); return (await Session.LoadAsync<T>(ids)).Select(x => x.Value).ToArray();
@@ -162,7 +162,7 @@ public partial class RavenOperations : IRavenOperations
/// </summary> /// </summary>
async Task<List<T>> GetDescendantsAndSelf<T>(T model) where T : MixtapeIdEntity, ISupportsTrees, new() async Task<List<T>> GetDescendantsAndSelf<T>(T model) where T : MixtapeIdEntity, ISupportsTrees, new()
{ {
List<T> items = new() { model }; List<T> items = [model];
async Task AddChildren(T parent) async Task AddChildren(T parent)
{ {
@@ -8,7 +8,7 @@ namespace Mixtape.Raven;
public class RavenDocumentConventionsBuilder : IRavenDocumentConventionsBuilder public class RavenDocumentConventionsBuilder : IRavenDocumentConventionsBuilder
{ {
protected HashSet<Type> PolymorphTypes { get; } = new(); protected HashSet<Type> PolymorphTypes { get; } = [];
protected Type AcceptsMixtapeConventionsType { get; set; } = typeof(ISupportsDbConventions); protected Type AcceptsMixtapeConventionsType { get; set; } = typeof(ISupportsDbConventions);
+1 -1
View File
@@ -32,7 +32,7 @@ public class RavenIndexesOptions : List<RavenIndexesOptions.Map>
} }
public RavenIndexModifiersOptions Modifiers { get; private set; } = new(); public RavenIndexModifiersOptions Modifiers { get; private set; } = [];
public void Add<T>() where T : IMixtapeIndexDefinition, new() public void Add<T>() where T : IMixtapeIndexDefinition, new()
{ {
+1 -1
View File
@@ -26,7 +26,7 @@ public class AssemblyDiscovery : IAssemblyDiscovery
/// <inheritdoc /> /// <inheritdoc />
public void Execute(IEnumerable<IAssemblyDiscoveryRule> rules) public void Execute(IEnumerable<IAssemblyDiscoveryRule> rules)
{ {
List<Assembly> assemblies = new List<Assembly>(); List<Assembly> assemblies = [];
DependencyContext dependencyContext = DependencyContext.Load(Context.EntryAssembly); DependencyContext dependencyContext = DependencyContext.Load(Context.EntryAssembly);
if (dependencyContext == null) if (dependencyContext == null)
@@ -5,7 +5,7 @@ namespace Mixtape.Communication;
public class MessageAggregator : IMessageAggregator public class MessageAggregator : IMessageAggregator
{ {
readonly ConcurrentBag<IMessageSubscription> Subscription = new ConcurrentBag<IMessageSubscription>(); readonly ConcurrentBag<IMessageSubscription> Subscription = [];
readonly IServiceProvider ServiceProvider; readonly IServiceProvider ServiceProvider;
+14 -14
View File
@@ -4,20 +4,20 @@ public static class CharExtensions
{ {
private static Dictionary<char, char[]> accents { get; } = new Dictionary<char, char[]>() private static Dictionary<char, char[]> accents { get; } = new Dictionary<char, char[]>()
{ {
{ 'ä', new char[2] { 'a', 'e' } }, { 'ä', ['a', 'e'] },
{ 'á', new char[1] { 'a' } }, { 'á', ['a'] },
{ 'à', new char[1] { 'a' } }, { 'à', ['a'] },
{ 'ó', new char[1] { 'o' } }, { 'ó', ['o'] },
{ 'ò', new char[1] { 'o' } }, { 'ò', ['o'] },
{ 'é', new char[1] { 'e' } }, { 'é', ['e'] },
{ 'è', new char[1] { 'e' } }, { 'è', ['e'] },
{ 'ú', new char[1] { 'u' } }, { 'ú', ['u'] },
{ 'ù', new char[1] { 'u' } }, { 'ù', ['u'] },
{ 'í', new char[1] { 'i' } }, { 'í', ['i'] },
{ 'ì', new char[1] { 'i' } }, { 'ì', ['i'] },
{ 'ö', new char[2] { 'o', 'e' } }, { 'ö', ['o', 'e'] },
{ 'ü', new char[2] { 'u', 'e' } }, { 'ü', ['u', 'e'] },
{ 'ß', new char[2] { 's', 's' } }, { 'ß', ['s', 's'] },
//{ '&', new char[1] { '+' } } //{ '&', new char[1] { '+' } }
}; };
+3 -3
View File
@@ -4,9 +4,9 @@ public static class NumberExtensions
{ {
static Dictionary<FileSizeNotation, string[]> FileSizeUnits = new() static Dictionary<FileSizeNotation, string[]> FileSizeUnits = new()
{ {
{ FileSizeNotation.SI, new string[] { "B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" } }, { FileSizeNotation.SI, ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] },
{ FileSizeNotation.IEC, new string[] { "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB" } }, { FileSizeNotation.IEC, ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"] },
{ FileSizeNotation.JEDEC, new string[] { "B", "KB", "MB", "GB" } } { FileSizeNotation.JEDEC, ["B", "KB", "MB", "GB"] }
}; };
public static int Limit(this int input, int min, int max) public static int Limit(this int input, int min, int max)
@@ -5,5 +5,5 @@ public abstract class MixtapeIdentityRole : MixtapeEntity
/// <summary> /// <summary>
/// The role's claims, for use in claims-based authentication. /// The role's claims, for use in claims-based authentication.
/// </summary> /// </summary>
public List<UserClaim> Claims { get; set; } = new(); public List<UserClaim> Claims { get; set; } = [];
} }
+1 -1
View File
@@ -78,7 +78,7 @@ public static class UserManagerExtensions
return Result<string[]>.Success(recoveryCodes.ToArray()); return Result<string[]>.Success(recoveryCodes.ToArray());
} }
return Result<string[]>.Success(Array.Empty<string>()); return Result<string[]>.Success([]);
} }
@@ -17,7 +17,7 @@ public class BlurWebProcessor : IImageWebProcessor
/// <summary> /// <summary>
/// The reusable collection of commands. /// The reusable collection of commands.
/// </summary> /// </summary>
private static readonly IEnumerable<string> BlurCommands = new[] { Blur }; private static readonly IEnumerable<string> BlurCommands = [Blur];
/// <inheritdoc/> /// <inheritdoc/>
public IEnumerable<string> Commands { get; } = BlurCommands; public IEnumerable<string> Commands { get; } = BlurCommands;
@@ -18,7 +18,7 @@ public class RotateWebProcessor : IImageWebProcessor
/// The reusable collection of commands. /// The reusable collection of commands.
/// </summary> /// </summary>
private static readonly IEnumerable<string> RotateCommands private static readonly IEnumerable<string> RotateCommands
= new[] { Rotate }; = [Rotate];
/// <inheritdoc/> /// <inheritdoc/>
public IEnumerable<string> Commands { get; } = RotateCommands; public IEnumerable<string> Commands { get; } = RotateCommands;
+1 -1
View File
@@ -20,7 +20,7 @@ public class FlavorProvider
[JsonIgnore] [JsonIgnore]
public Func<object> FlavorlessConstruct { get; set; } public Func<object> FlavorlessConstruct { get; set; }
public List<FlavorConfig> Flavors { get; set; } = new(); public List<FlavorConfig> Flavors { get; set; } = [];
/// <summary> /// <summary>
/// Flavor discriminator converter /// Flavor discriminator converter
+1 -1
View File
@@ -11,7 +11,7 @@ public class Result
public bool IsSuccess { get; set; } public bool IsSuccess { get; set; }
[DataMember(Name = "errors")] [DataMember(Name = "errors")]
public List<ResultError> Errors { get; set; } = new(); public List<ResultError> Errors { get; set; } = [];
public Result() { } public Result() { }
+1 -1
View File
@@ -24,7 +24,7 @@ public class UrlResult
public class UrlsResult public class UrlsResult
{ {
public string[] Urls { get; set; } = Array.Empty<string>(); public string[] Urls { get; set; } = [];
public string Domain { get; set; } public string Domain { get; set; }
+1 -1
View File
@@ -43,7 +43,7 @@ public class Number : MixtapeEntity
/// <summary> /// <summary>
/// Store current counters /// Store current counters
/// </summary> /// </summary>
public List<NumberCounter> Counters { get; set; } = new(); public List<NumberCounter> Counters { get; set; } = [];
/// <summary> /// <summary>
/// Post process the compiled number /// Post process the compiled number
+1 -1
View File
@@ -115,7 +115,7 @@ public class Numbers : INumbers
return; return;
} }
number.Counters = new(); number.Counters = [];
await Db.Update(number); await Db.Update(number);
} }
+3 -3
View File
@@ -108,7 +108,7 @@ public class QrCode
Objects.RequireNonNull(data); Objects.RequireNonNull(data);
Objects.RequireNonNull(ecl); Objects.RequireNonNull(ecl);
var seg = QrSegment.MakeBytes(data); var seg = QrSegment.MakeBytes(data);
return EncodeSegments(new List<QrSegment> { seg }, ecl); return EncodeSegments([seg], ecl);
} }
#endregion #endregion
@@ -1030,7 +1030,7 @@ public class QrCode
{ {
if (Version == 1) if (Version == 1)
{ {
return new int[] { }; return [];
} }
var numAlign = Version / 7 + 2; var numAlign = Version / 7 + 2;
@@ -1292,7 +1292,7 @@ public class QrCode
public static readonly Ecc High = new Ecc(3, 2); public static readonly Ecc High = new Ecc(3, 2);
internal static readonly Ecc[] AllValues = { Low, Medium, Quartile, High }; internal static readonly Ecc[] AllValues = [Low, Medium, Quartile, High];
/// <summary> /// <summary>
/// Ordinal number of error correction level (in the range 0 to 3). /// Ordinal number of error correction level (in the range 0 to 3).
@@ -106,7 +106,7 @@ public static class QrSegmentAdvanced
private static List<QrSegment> MakeSegmentsOptimally(int[] codePoints, int version) private static List<QrSegment> MakeSegmentsOptimally(int[] codePoints, int version)
{ {
if (codePoints.Length == 0) if (codePoints.Length == 0)
return new List<QrSegment>(); return [];
var charModes = ComputeCharacterModes(codePoints, version); var charModes = ComputeCharacterModes(codePoints, version);
return SplitIntoSegments(codePoints, charModes); return SplitIntoSegments(codePoints, charModes);
} }
@@ -120,7 +120,7 @@ public static class QrSegmentAdvanced
throw new ArgumentOutOfRangeException(nameof(codePoints)); throw new ArgumentOutOfRangeException(nameof(codePoints));
} }
Mode[] modeTypes = { Mode.Byte, Mode.Alphanumeric, Mode.Numeric, Mode.Kanji }; // Do not modify Mode[] modeTypes = [Mode.Byte, Mode.Alphanumeric, Mode.Numeric, Mode.Kanji]; // Do not modify
var numModes = modeTypes.Length; var numModes = modeTypes.Length;
// Segment header sizes, measured in 1/6 bits // Segment header sizes, measured in 1/6 bits
+1 -1
View File
@@ -9,7 +9,7 @@ public class RequestUrlResolver : IRequestUrlResolver
protected ILogger<RequestUrlResolver> Logger { get; } protected ILogger<RequestUrlResolver> Logger { get; }
static string[] Protocols = new[] { "http://", "https://", "ftp://", "ftps://", "sftp://", "udp://" }; static string[] Protocols = ["http://", "https://", "ftp://", "ftps://", "sftp://", "udp://"];
public RequestUrlResolver(IHttpContextAccessor httpContextAccessor, ILogger<RequestUrlResolver> logger) public RequestUrlResolver(IHttpContextAccessor httpContextAccessor, ILogger<RequestUrlResolver> logger)
+1 -1
View File
@@ -44,7 +44,7 @@ public static class Base32
input = input.TrimEnd('=').ToUpperInvariant(); input = input.TrimEnd('=').ToUpperInvariant();
if (input.Length == 0) if (input.Length == 0)
{ {
return new byte[0]; return [];
} }
var output = new byte[input.Length * 5 / 8]; var output = new byte[input.Length * 5 / 8];
+6 -6
View File
@@ -18,8 +18,8 @@ public class ObjectTraverser
/// </summary> /// </summary>
public static List<Result<T>> Find<T>(object value) where T : class public static List<Result<T>> Find<T>(object value) where T : class
{ {
HashSet<object> exploredObjects = new HashSet<object>(); HashSet<object> exploredObjects = [];
List<Result<T>> found = new List<Result<T>>(); List<Result<T>> found = [];
Find<T>(value, null, string.Empty, null, exploredObjects, found); Find<T>(value, null, string.Empty, null, exploredObjects, found);
@@ -32,8 +32,8 @@ public class ObjectTraverser
/// </summary> /// </summary>
public static List<Result> Find(Type type, object value) public static List<Result> Find(Type type, object value)
{ {
HashSet<object> exploredObjects = new HashSet<object>(); HashSet<object> exploredObjects = [];
List<Result> found = new List<Result>(); List<Result> found = [];
Find(type, value, null, string.Empty, null, exploredObjects, found); Find(type, value, null, string.Empty, null, exploredObjects, found);
@@ -46,8 +46,8 @@ public class ObjectTraverser
/// </summary> /// </summary>
public static List<Result<T>> FindAttribute<T>(object value) where T : Attribute public static List<Result<T>> FindAttribute<T>(object value) where T : Attribute
{ {
HashSet<string> exploredObjects = new HashSet<string>(); HashSet<string> exploredObjects = [];
List<Result<T>> found = new List<Result<T>>(); List<Result<T>> found = [];
FindAttribute<T>(value, null, string.Empty, null, exploredObjects, found); FindAttribute<T>(value, null, string.Empty, null, exploredObjects, found);
+1 -1
View File
@@ -15,7 +15,7 @@ public class Safenames
const char DOT = '.'; const char DOT = '.';
static char[] TICKS = new char[3] { '`', '\'', '´' }; static char[] TICKS = ['`', '\'', '´'];
/// <summary> /// <summary>