Skip to content

Commit 79529ee

Browse files
author
Ahmad
committed
list initializer
1 parent e5ef201 commit 79529ee

File tree

10 files changed

+21
-23
lines changed

10 files changed

+21
-23
lines changed

QueryBuilder.Tests/ParameterTypeTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public enum EnumExample {
1616
}
1717

1818
public class ParameterTypeGenerator : IEnumerable<object[]> {
19-
private readonly List<object[]> _data = new List<object[]>
20-
{
19+
private readonly List<object[]> _data =
20+
[
2121
new object[] {"1", 1},
2222
new object[] {Convert.ToSingle("10.5", CultureInfo.InvariantCulture).ToString(), 10.5},
2323
new object[] {"-2", -2},
@@ -28,7 +28,7 @@ public class ParameterTypeGenerator : IEnumerable<object[]> {
2828
new object[] {"0 /* First */", EnumExample.First},
2929
new object[] {"1 /* Second */", EnumExample.Second},
3030
new object[] {"'a string'", "a string"},
31-
};
31+
];
3232

3333
public IEnumerator<object[]> GetEnumerator() => _data.GetEnumerator();
3434

QueryBuilder/BaseQuery.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public abstract class AbstractQuery {
99
}
1010

1111
public abstract partial class BaseQuery<Q> : AbstractQuery where Q : BaseQuery<Q> {
12-
public List<AbstractClause> Clauses { get; set; } = new List<AbstractClause>();
12+
public List<AbstractClause> Clauses { get; set; } = [];
1313

1414
private bool orFlag = false;
1515
private bool notFlag = false;

QueryBuilder/Compilers/Compiler.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,18 @@ protected Compiler() {
4545
/// A list of white-listed operators
4646
/// </summary>
4747
/// <value></value>
48-
protected readonly HashSet<string> operators = new HashSet<string>
49-
{
48+
protected readonly HashSet<string> operators =
49+
[
5050
"=", "<", ">", "<=", ">=", "<>", "!=", "<=>",
5151
"like", "not like",
5252
"ilike", "not ilike",
5353
"like binary", "not like binary",
5454
"rlike", "not rlike",
5555
"regexp", "not regexp",
5656
"similar to", "not similar to"
57-
};
57+
];
5858

59-
protected HashSet<string> userOperators = new HashSet<string> {
60-
61-
};
59+
protected HashSet<string> userOperators = [];
6260

6361
protected Dictionary<string, object> generateNamedBindings(object[] bindings) {
6462
return Helper.Flatten(bindings).Select((v, i) => new { i, v })
@@ -89,7 +87,7 @@ private Query TransformAggregateQuery(Query query) {
8987
}
9088

9189
var outerClause = new AggregateClause() {
92-
Columns = new List<string> { "*" },
90+
Columns = ["*"],
9391
Type = clause.Type
9492
};
9593

QueryBuilder/Compilers/ConditionsCompilerProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace SqlKata.Compilers;
77

88
internal class ConditionsCompilerProvider {
99
private readonly Type compilerType;
10-
private readonly Dictionary<string, MethodInfo> methodsCache = new Dictionary<string, MethodInfo>();
10+
private readonly Dictionary<string, MethodInfo> methodsCache = [];
1111
private readonly object syncRoot = new object();
1212

1313
public ConditionsCompilerProvider(Compiler compiler) {

QueryBuilder/Compilers/CteFinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public List<AbstractFrom> Find() {
1717
if (null != orderedCteList)
1818
return orderedCteList;
1919

20-
namesOfPreviousCtes = new HashSet<string>();
20+
namesOfPreviousCtes = [];
2121

2222
orderedCteList = findInternal(query);
2323

QueryBuilder/Helper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public static List<string> ExpandExpression(string expression) {
119119

120120
if (!match.Success) {
121121
// we did not found a match return the string as is.
122-
return new List<string> { expression };
122+
return [expression];
123123
}
124124

125125
var table = expression.Substring(0, expression.IndexOf(".{"));

QueryBuilder/Query.Aggregate.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ public Query AsAggregate(string type, string[] columns = null) {
1111
this.ClearComponent("aggregate")
1212
.AddComponent("aggregate", new AggregateClause {
1313
Type = type,
14-
Columns = columns?.ToList() ?? new List<string>(),
14+
Columns = columns?.ToList() ?? [],
1515
});
1616

1717
return this;
1818
}
1919

2020
public Query AsCount(string[] columns = null) {
21-
var cols = columns?.ToList() ?? new List<string> { };
21+
var cols = columns?.ToList() ?? [];
2222

2323
if (!cols.Any()) {
2424
cols.Add("*");

QueryBuilder/Query.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ public partial class Query : BaseQuery<Query> {
1212
public bool IsDistinct { get; set; } = false;
1313
public string QueryAlias { get; set; }
1414
public string Method { get; set; } = "select";
15-
public List<Include> Includes = new List<Include>();
16-
public Dictionary<string, object> Variables = new Dictionary<string, object>();
15+
public List<Include> Includes = [];
16+
public Dictionary<string, object> Variables = [];
1717

1818
public Query() : base() {
1919
}
@@ -125,7 +125,7 @@ public Query With(string alias, IEnumerable<string> columns, IEnumerable<IEnumer
125125
var clause = new AdHocTableFromClause() {
126126
Alias = alias,
127127
Columns = columnsList,
128-
Values = new List<object>(),
128+
Values = [],
129129
};
130130

131131
foreach (var values in valuesCollectionList) {

QueryBuilder/SqlResult.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ public SqlResult(string parameterPlaceholder, string escapeCharacter) {
1515
}
1616
public Query Query { get; set; }
1717
public string RawSql { get; set; } = "";
18-
public List<object> Bindings { get; set; } = new List<object>();
18+
public List<object> Bindings { get; set; } = [];
1919
public string Sql { get; set; } = "";
20-
public Dictionary<string, object> NamedBindings = new Dictionary<string, object>();
20+
public Dictionary<string, object> NamedBindings = [];
2121

2222
private static readonly Type[] NumberTypes =
2323
{

SqlKata.Execution/QueryFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ private static IEnumerable<T> handleIncludes<T>(Query query, IEnumerable<T> resu
632632

633633
foreach (var item in dynamicResult) {
634634
var localValue = item[include.LocalKey].ToString();
635-
item[include.Name] = children.ContainsKey(localValue) ? children[localValue] : new List<Dictionary<string, object>>();
635+
item[include.Name] = children.ContainsKey(localValue) ? children[localValue] : [];
636636
}
637637

638638
continue;
@@ -718,7 +718,7 @@ private static async Task<IEnumerable<T>> handleIncludesAsync<T>(Query query, IE
718718

719719
foreach (var item in dynamicResult) {
720720
var localValue = item[include.LocalKey].ToString();
721-
item[include.Name] = children.ContainsKey(localValue) ? children[localValue] : new List<Dictionary<string, object>>();
721+
item[include.Name] = children.ContainsKey(localValue) ? children[localValue] : [];
722722
}
723723

724724
continue;

0 commit comments

Comments
 (0)