use collection expressions
This commit is contained in:
@@ -92,7 +92,7 @@ public static class RavenQueryableExtensions
|
||||
|
||||
searchTerms = searchTerms.Trim();
|
||||
|
||||
string[] searchParts = searchTerms.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x =>
|
||||
string[] searchParts = searchTerms.Split([" "], StringSplitOptions.RemoveEmptyEntries).Select(x =>
|
||||
{
|
||||
if (suffix != null)
|
||||
{
|
||||
@@ -107,7 +107,7 @@ public static class RavenQueryableExtensions
|
||||
|
||||
if (searchTerms.StartsWith('"') && searchTerms.EndsWith('"'))
|
||||
{
|
||||
searchParts = new[] { searchTerms };
|
||||
searchParts = [searchTerms];
|
||||
}
|
||||
|
||||
return source.Search(fieldSelector, searchParts, @operator: @operator);
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace Mixtape.Raven;
|
||||
|
||||
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
|
||||
|
||||
@@ -50,7 +50,7 @@ internal class MixtapeRavenModule : MixtapeModule
|
||||
IDocumentStore store = new DocumentStore()
|
||||
{
|
||||
Database = ravenOptions.Database,
|
||||
Urls = new string[1] { ravenOptions.Url },
|
||||
Urls = [ravenOptions.Url],
|
||||
Conventions =
|
||||
{
|
||||
AggressiveCache =
|
||||
|
||||
@@ -46,7 +46,7 @@ public partial class RavenOperations : IRavenOperations
|
||||
ids = ids.Distinct().ToArray();
|
||||
|
||||
Dictionary<string, T> models = await Session.LoadAsync<T>(ids);
|
||||
List<T> result = new();
|
||||
List<T> result = [];
|
||||
|
||||
foreach (string id in ids)
|
||||
{
|
||||
@@ -148,7 +148,7 @@ public partial class RavenOperations : IRavenOperations
|
||||
/// <inheritdoc />
|
||||
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))
|
||||
{
|
||||
|
||||
@@ -25,10 +25,10 @@ public partial class RavenOperations : IRavenOperations
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
return Array.Empty<T>();
|
||||
return [];
|
||||
}
|
||||
|
||||
List<string> ids = result.Path ?? new();
|
||||
List<string> ids = result.Path ?? [];
|
||||
ids.Add(id);
|
||||
|
||||
return (await Session.LoadAsync<T>(ids)).Select(x => x.Value).ToArray();
|
||||
@@ -162,7 +162,7 @@ public partial class RavenOperations : IRavenOperations
|
||||
/// </summary>
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Mixtape.Raven;
|
||||
|
||||
public class RavenDocumentConventionsBuilder : IRavenDocumentConventionsBuilder
|
||||
{
|
||||
protected HashSet<Type> PolymorphTypes { get; } = new();
|
||||
protected HashSet<Type> PolymorphTypes { get; } = [];
|
||||
|
||||
protected Type AcceptsMixtapeConventionsType { get; set; } = typeof(ISupportsDbConventions);
|
||||
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -26,7 +26,7 @@ public class AssemblyDiscovery : IAssemblyDiscovery
|
||||
/// <inheritdoc />
|
||||
public void Execute(IEnumerable<IAssemblyDiscoveryRule> rules)
|
||||
{
|
||||
List<Assembly> assemblies = new List<Assembly>();
|
||||
List<Assembly> assemblies = [];
|
||||
DependencyContext dependencyContext = DependencyContext.Load(Context.EntryAssembly);
|
||||
|
||||
if (dependencyContext == null)
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Mixtape.Communication;
|
||||
|
||||
public class MessageAggregator : IMessageAggregator
|
||||
{
|
||||
readonly ConcurrentBag<IMessageSubscription> Subscription = new ConcurrentBag<IMessageSubscription>();
|
||||
readonly ConcurrentBag<IMessageSubscription> Subscription = [];
|
||||
readonly IServiceProvider ServiceProvider;
|
||||
|
||||
|
||||
|
||||
@@ -4,20 +4,20 @@ public static class CharExtensions
|
||||
{
|
||||
private static Dictionary<char, char[]> accents { get; } = new Dictionary<char, char[]>()
|
||||
{
|
||||
{ 'ä', new char[2] { 'a', 'e' } },
|
||||
{ 'á', new char[1] { 'a' } },
|
||||
{ 'à', new char[1] { 'a' } },
|
||||
{ 'ó', new char[1] { 'o' } },
|
||||
{ 'ò', new char[1] { 'o' } },
|
||||
{ 'é', new char[1] { 'e' } },
|
||||
{ 'è', new char[1] { 'e' } },
|
||||
{ 'ú', new char[1] { 'u' } },
|
||||
{ 'ù', new char[1] { 'u' } },
|
||||
{ 'í', new char[1] { 'i' } },
|
||||
{ 'ì', new char[1] { 'i' } },
|
||||
{ 'ö', new char[2] { 'o', 'e' } },
|
||||
{ 'ü', new char[2] { 'u', 'e' } },
|
||||
{ 'ß', new char[2] { 's', 's' } },
|
||||
{ 'ä', ['a', 'e'] },
|
||||
{ 'á', ['a'] },
|
||||
{ 'à', ['a'] },
|
||||
{ 'ó', ['o'] },
|
||||
{ 'ò', ['o'] },
|
||||
{ 'é', ['e'] },
|
||||
{ 'è', ['e'] },
|
||||
{ 'ú', ['u'] },
|
||||
{ 'ù', ['u'] },
|
||||
{ 'í', ['i'] },
|
||||
{ 'ì', ['i'] },
|
||||
{ 'ö', ['o', 'e'] },
|
||||
{ 'ü', ['u', 'e'] },
|
||||
{ 'ß', ['s', 's'] },
|
||||
//{ '&', new char[1] { '+' } }
|
||||
};
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@ public static class NumberExtensions
|
||||
{
|
||||
static Dictionary<FileSizeNotation, string[]> FileSizeUnits = new()
|
||||
{
|
||||
{ FileSizeNotation.SI, new string[] { "B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" } },
|
||||
{ FileSizeNotation.IEC, new string[] { "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB" } },
|
||||
{ FileSizeNotation.JEDEC, new string[] { "B", "KB", "MB", "GB" } }
|
||||
{ FileSizeNotation.SI, ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] },
|
||||
{ FileSizeNotation.IEC, ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"] },
|
||||
{ FileSizeNotation.JEDEC, ["B", "KB", "MB", "GB"] }
|
||||
};
|
||||
|
||||
public static int Limit(this int input, int min, int max)
|
||||
|
||||
@@ -5,5 +5,5 @@ public abstract class MixtapeIdentityRole : MixtapeEntity
|
||||
/// <summary>
|
||||
/// The role's claims, for use in claims-based authentication.
|
||||
/// </summary>
|
||||
public List<UserClaim> Claims { get; set; } = new();
|
||||
public List<UserClaim> Claims { get; set; } = [];
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ public static class UserManagerExtensions
|
||||
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>
|
||||
/// The reusable collection of commands.
|
||||
/// </summary>
|
||||
private static readonly IEnumerable<string> BlurCommands = new[] { Blur };
|
||||
private static readonly IEnumerable<string> BlurCommands = [Blur];
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IEnumerable<string> Commands { get; } = BlurCommands;
|
||||
|
||||
@@ -18,7 +18,7 @@ public class RotateWebProcessor : IImageWebProcessor
|
||||
/// The reusable collection of commands.
|
||||
/// </summary>
|
||||
private static readonly IEnumerable<string> RotateCommands
|
||||
= new[] { Rotate };
|
||||
= [Rotate];
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IEnumerable<string> Commands { get; } = RotateCommands;
|
||||
|
||||
@@ -20,7 +20,7 @@ public class FlavorProvider
|
||||
[JsonIgnore]
|
||||
public Func<object> FlavorlessConstruct { get; set; }
|
||||
|
||||
public List<FlavorConfig> Flavors { get; set; } = new();
|
||||
public List<FlavorConfig> Flavors { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Flavor discriminator converter
|
||||
|
||||
@@ -11,7 +11,7 @@ public class Result
|
||||
public bool IsSuccess { get; set; }
|
||||
|
||||
[DataMember(Name = "errors")]
|
||||
public List<ResultError> Errors { get; set; } = new();
|
||||
public List<ResultError> Errors { get; set; } = [];
|
||||
|
||||
public Result() { }
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public class UrlResult
|
||||
|
||||
public class UrlsResult
|
||||
{
|
||||
public string[] Urls { get; set; } = Array.Empty<string>();
|
||||
public string[] Urls { get; set; } = [];
|
||||
|
||||
public string Domain { get; set; }
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public class Number : MixtapeEntity
|
||||
/// <summary>
|
||||
/// Store current counters
|
||||
/// </summary>
|
||||
public List<NumberCounter> Counters { get; set; } = new();
|
||||
public List<NumberCounter> Counters { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Post process the compiled number
|
||||
|
||||
@@ -115,7 +115,7 @@ public class Numbers : INumbers
|
||||
return;
|
||||
}
|
||||
|
||||
number.Counters = new();
|
||||
number.Counters = [];
|
||||
await Db.Update(number);
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ public class QrCode
|
||||
Objects.RequireNonNull(data);
|
||||
Objects.RequireNonNull(ecl);
|
||||
var seg = QrSegment.MakeBytes(data);
|
||||
return EncodeSegments(new List<QrSegment> { seg }, ecl);
|
||||
return EncodeSegments([seg], ecl);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -1030,7 +1030,7 @@ public class QrCode
|
||||
{
|
||||
if (Version == 1)
|
||||
{
|
||||
return new int[] { };
|
||||
return [];
|
||||
}
|
||||
|
||||
var numAlign = Version / 7 + 2;
|
||||
@@ -1292,7 +1292,7 @@ public class QrCode
|
||||
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>
|
||||
/// 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)
|
||||
{
|
||||
if (codePoints.Length == 0)
|
||||
return new List<QrSegment>();
|
||||
return [];
|
||||
var charModes = ComputeCharacterModes(codePoints, version);
|
||||
return SplitIntoSegments(codePoints, charModes);
|
||||
}
|
||||
@@ -120,7 +120,7 @@ public static class QrSegmentAdvanced
|
||||
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;
|
||||
|
||||
// Segment header sizes, measured in 1/6 bits
|
||||
|
||||
@@ -9,7 +9,7 @@ public class RequestUrlResolver : IRequestUrlResolver
|
||||
|
||||
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)
|
||||
|
||||
@@ -44,7 +44,7 @@ public static class Base32
|
||||
input = input.TrimEnd('=').ToUpperInvariant();
|
||||
if (input.Length == 0)
|
||||
{
|
||||
return new byte[0];
|
||||
return [];
|
||||
}
|
||||
|
||||
var output = new byte[input.Length * 5 / 8];
|
||||
|
||||
@@ -18,8 +18,8 @@ public class ObjectTraverser
|
||||
/// </summary>
|
||||
public static List<Result<T>> Find<T>(object value) where T : class
|
||||
{
|
||||
HashSet<object> exploredObjects = new HashSet<object>();
|
||||
List<Result<T>> found = new List<Result<T>>();
|
||||
HashSet<object> exploredObjects = [];
|
||||
List<Result<T>> found = [];
|
||||
|
||||
Find<T>(value, null, string.Empty, null, exploredObjects, found);
|
||||
|
||||
@@ -32,8 +32,8 @@ public class ObjectTraverser
|
||||
/// </summary>
|
||||
public static List<Result> Find(Type type, object value)
|
||||
{
|
||||
HashSet<object> exploredObjects = new HashSet<object>();
|
||||
List<Result> found = new List<Result>();
|
||||
HashSet<object> exploredObjects = [];
|
||||
List<Result> found = [];
|
||||
|
||||
Find(type, value, null, string.Empty, null, exploredObjects, found);
|
||||
|
||||
@@ -46,8 +46,8 @@ public class ObjectTraverser
|
||||
/// </summary>
|
||||
public static List<Result<T>> FindAttribute<T>(object value) where T : Attribute
|
||||
{
|
||||
HashSet<string> exploredObjects = new HashSet<string>();
|
||||
List<Result<T>> found = new List<Result<T>>();
|
||||
HashSet<string> exploredObjects = [];
|
||||
List<Result<T>> found = [];
|
||||
|
||||
FindAttribute<T>(value, null, string.Empty, null, exploredObjects, found);
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ public class Safenames
|
||||
|
||||
const char DOT = '.';
|
||||
|
||||
static char[] TICKS = new char[3] { '`', '\'', '´' };
|
||||
static char[] TICKS = ['`', '\'', '´'];
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user