Skip to content

Commit 875ac54

Browse files
committed
Resharper: Use collection expression
1 parent f3f382a commit 875ac54

File tree

73 files changed

+193
-245
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+193
-245
lines changed

JsonApiDotNetCore.sln.DotSettings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ JsonApiDotNetCore.ArgumentGuard.NotNull($EXPR$);</s:String>
9393
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseNegatedPatternInIsExpression/@EntryIndexedValue">SUGGESTION</s:String>
9494
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseNegatedPatternMatching/@EntryIndexedValue">SUGGESTION</s:String>
9595
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=VirtualMemberNeverOverridden_002ELocal/@EntryIndexedValue">WARNING</s:String>
96+
<s:String x:Key="/Default/CodeInspection/Highlighting/UseCollectionExpression/ConvertEmptyCollection/@EntryValue">SUGGESTION</s:String>
9697
<s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=JADNC_0020Full_0020Cleanup/@EntryIndexedValue">&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;Profile name="JADNC Full Cleanup"&gt;&lt;XMLReformatCode&gt;True&lt;/XMLReformatCode&gt;&lt;CSCodeStyleAttributes ArrangeTypeAccessModifier="True" ArrangeTypeMemberAccessModifier="True" SortModifiers="True" RemoveRedundantParentheses="True" AddMissingParentheses="True" ArrangeBraces="True" ArrangeAttributes="True" ArrangeArgumentsStyle="True" ArrangeCodeBodyStyle="True" ArrangeVarStyle="True" ArrangeTrailingCommas="True" ArrangeObjectCreation="True" ArrangeDefaultValue="True" ArrangeNamespaces="True" ArrangeNullCheckingPattern="True" /&gt;&lt;CssAlphabetizeProperties&gt;True&lt;/CssAlphabetizeProperties&gt;&lt;JsInsertSemicolon&gt;True&lt;/JsInsertSemicolon&gt;&lt;FormatAttributeQuoteDescriptor&gt;True&lt;/FormatAttributeQuoteDescriptor&gt;&lt;CorrectVariableKindsDescriptor&gt;True&lt;/CorrectVariableKindsDescriptor&gt;&lt;VariablesToInnerScopesDescriptor&gt;True&lt;/VariablesToInnerScopesDescriptor&gt;&lt;StringToTemplatesDescriptor&gt;True&lt;/StringToTemplatesDescriptor&gt;&lt;JsReformatCode&gt;True&lt;/JsReformatCode&gt;&lt;JsFormatDocComments&gt;True&lt;/JsFormatDocComments&gt;&lt;RemoveRedundantQualifiersTs&gt;True&lt;/RemoveRedundantQualifiersTs&gt;&lt;OptimizeImportsTs&gt;True&lt;/OptimizeImportsTs&gt;&lt;OptimizeReferenceCommentsTs&gt;True&lt;/OptimizeReferenceCommentsTs&gt;&lt;PublicModifierStyleTs&gt;True&lt;/PublicModifierStyleTs&gt;&lt;ExplicitAnyTs&gt;True&lt;/ExplicitAnyTs&gt;&lt;TypeAnnotationStyleTs&gt;True&lt;/TypeAnnotationStyleTs&gt;&lt;RelativePathStyleTs&gt;True&lt;/RelativePathStyleTs&gt;&lt;AsInsteadOfCastTs&gt;True&lt;/AsInsteadOfCastTs&gt;&lt;HtmlReformatCode&gt;True&lt;/HtmlReformatCode&gt;&lt;AspOptimizeRegisterDirectives&gt;True&lt;/AspOptimizeRegisterDirectives&gt;&lt;RemoveCodeRedundancies&gt;True&lt;/RemoveCodeRedundancies&gt;&lt;CSUseAutoProperty&gt;True&lt;/CSUseAutoProperty&gt;&lt;CSMakeFieldReadonly&gt;True&lt;/CSMakeFieldReadonly&gt;&lt;CSMakeAutoPropertyGetOnly&gt;True&lt;/CSMakeAutoPropertyGetOnly&gt;&lt;CSArrangeQualifiers&gt;True&lt;/CSArrangeQualifiers&gt;&lt;CSFixBuiltinTypeReferences&gt;True&lt;/CSFixBuiltinTypeReferences&gt;&lt;CssReformatCode&gt;True&lt;/CssReformatCode&gt;&lt;CSOptimizeUsings&gt;&lt;OptimizeUsings&gt;True&lt;/OptimizeUsings&gt;&lt;/CSOptimizeUsings&gt;&lt;CSShortenReferences&gt;True&lt;/CSShortenReferences&gt;&lt;CSReformatCode&gt;True&lt;/CSReformatCode&gt;&lt;CSharpFormatDocComments&gt;True&lt;/CSharpFormatDocComments&gt;&lt;CSReorderTypeMembers&gt;True&lt;/CSReorderTypeMembers&gt;&lt;XAMLCollapseEmptyTags&gt;False&lt;/XAMLCollapseEmptyTags&gt;&lt;CSReformatInactiveBranches&gt;True&lt;/CSReformatInactiveBranches&gt;&lt;/Profile&gt;</s:String>
9798
<s:String x:Key="/Default/CodeStyle/CodeCleanup/SilentCleanupProfile/@EntryValue">JADNC Full Cleanup</s:String>
9899
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_FOR_FOR/@EntryValue">Required</s:String>
@@ -125,6 +126,7 @@ JsonApiDotNetCore.ArgumentGuard.NotNull($EXPR$);</s:String>
125126
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_EXISTING_SWITCH_EXPRESSION_ARRANGEMENT/@EntryValue">False</s:Boolean>
126127
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_USER_LINEBREAKS/@EntryValue">False</s:Boolean>
127128
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/LINE_FEED_AT_FILE_END/@EntryValue">True</s:Boolean>
129+
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/MAX_ARRAY_INITIALIZER_ELEMENTS_ON_LINE/@EntryValue">1</s:Int64>
128130
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_ACCESSOR_ATTRIBUTE_ON_SAME_LINE_EX/@EntryValue">NEVER</s:String>
129131
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_ACCESSORHOLDER_ATTRIBUTE_ON_SAME_LINE_EX/@EntryValue">NEVER</s:String>
130132
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_CONSTRUCTOR_INITIALIZER_ON_SAME_LINE/@EntryValue">False</s:Boolean>
@@ -145,6 +147,7 @@ JsonApiDotNetCore.ArgumentGuard.NotNull($EXPR$);</s:String>
145147
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_BEFORE_LINQ_EXPRESSION/@EntryValue">True</s:Boolean>
146148
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_FOR_STMT_HEADER_STYLE/@EntryValue">WRAP_IF_LONG</s:String>
147149
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LIMIT/@EntryValue">160</s:Int64>
150+
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LIST_PATTERN/@EntryValue">CHOP_IF_LONG</s:String>
148151
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_MULTIPLE_DECLARATION_STYLE/@EntryValue">WRAP_IF_LONG</s:String>
149152
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_MULTIPLE_TYPE_PARAMEER_CONSTRAINTS_STYLE/@EntryValue">CHOP_ALWAYS</s:String>
150153
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_OBJECT_AND_COLLECTION_INITIALIZER_STYLE/@EntryValue">CHOP_ALWAYS</s:String>

WarningSeverities.DotSettings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@
240240
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseAwaitUsing/@EntryIndexedValue">WARNING</s:String>
241241
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseCancellationTokenForIAsyncEnumerable/@EntryIndexedValue">WARNING</s:String>
242242
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseCollectionCountProperty/@EntryIndexedValue">WARNING</s:String>
243+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseCollectionExpression/@EntryIndexedValue">WARNING</s:String>
243244
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseFormatSpecifierInFormatString/@EntryIndexedValue">WARNING</s:String>
244245
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseFormatSpecifierInInterpolation/@EntryIndexedValue">WARNING</s:String>
245246
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseIndexFromEndExpression/@EntryIndexedValue">WARNING</s:String>
@@ -264,4 +265,5 @@
264265
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=VirtualMemberNeverOverridden_002ELocal/@EntryIndexedValue">WARNING</s:String>
265266
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=WithExpressionInsteadOfInitializer/@EntryIndexedValue">WARNING</s:String>
266267
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=WrongIndentSize/@EntryIndexedValue">WARNING</s:String>
268+
<s:String x:Key="/Default/CodeInspection/Highlighting/UseCollectionExpression/ConvertEmptyCollection/@EntryValue">WARNING</s:String>
267269
</wpf:ResourceDictionary>

src/Examples/DapperExample/Data/RotatingList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ internal abstract class RotatingList
44
{
55
public static RotatingList<T> Create<T>(int count, Func<int, T> createElement)
66
{
7-
List<T> elements = new();
7+
List<T> elements = [];
88

99
for (int index = 0; index < count; index++)
1010
{

src/Examples/DapperExample/Definitions/TodoItemDefinition.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ public override SortExpression OnApplySort(SortExpression? existingSort)
2929

3030
private SortExpression GetDefaultSortOrder()
3131
{
32-
return CreateSortExpressionFromLambda(new PropertySortOrder
33-
{
32+
return CreateSortExpressionFromLambda([
3433
(todoItem => todoItem.Priority, ListSortDirection.Ascending),
3534
(todoItem => todoItem.LastModifiedAt, ListSortDirection.Descending)
36-
});
35+
]);
3736
}
3837

3938
public override Task OnWritingAsync(TodoItem resource, WriteOperationKind writeOperation, CancellationToken cancellationToken)

src/Examples/DapperExample/Repositories/DapperFacade.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public IReadOnlyCollection<CommandDefinition> BuildSqlCommandsForOneToOneRelatio
3838
{
3939
ArgumentGuard.NotNull(changeDetector);
4040

41-
List<CommandDefinition> sqlCommands = new();
41+
List<CommandDefinition> sqlCommands = [];
4242

4343
foreach ((HasOneAttribute relationship, (object? currentRightId, object newRightId)) in changeDetector.GetOneToOneRelationshipsChangedToNotNull())
4444
{
@@ -81,7 +81,7 @@ public IReadOnlyCollection<CommandDefinition> BuildSqlCommandsForChangedRelation
8181
{
8282
ArgumentGuard.NotNull(changeDetector);
8383

84-
List<CommandDefinition> sqlCommands = new();
84+
List<CommandDefinition> sqlCommands = [];
8585

8686
foreach ((HasOneAttribute hasOneRelationship, (object? currentRightId, object? newRightId)) in changeDetector
8787
.GetChangedToOneRelationshipsWithForeignKeyAtRightSide())

src/Examples/DapperExample/Repositories/ResourceChangeDetector.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ internal sealed class ResourceChangeDetector
1515
private readonly CollectionConverter _collectionConverter = new();
1616
private readonly IDataModelService _dataModelService;
1717

18-
private Dictionary<string, object?> _currentColumnValues = new();
19-
private Dictionary<string, object?> _newColumnValues = new();
18+
private Dictionary<string, object?> _currentColumnValues = [];
19+
private Dictionary<string, object?> _newColumnValues = [];
2020

21-
private Dictionary<RelationshipAttribute, ISet<IIdentifiable>> _currentRightResourcesByRelationship = new();
22-
private Dictionary<RelationshipAttribute, ISet<IIdentifiable>> _newRightResourcesByRelationship = new();
21+
private Dictionary<RelationshipAttribute, ISet<IIdentifiable>> _currentRightResourcesByRelationship = [];
22+
private Dictionary<RelationshipAttribute, ISet<IIdentifiable>> _newRightResourcesByRelationship = [];
2323

2424
public ResourceType ResourceType { get; }
2525

@@ -52,7 +52,7 @@ public void CaptureNewValues(IIdentifiable resource)
5252

5353
private Dictionary<string, object?> CaptureColumnValues(IIdentifiable resource)
5454
{
55-
Dictionary<string, object?> columnValues = new();
55+
Dictionary<string, object?> columnValues = [];
5656

5757
foreach ((string columnName, ResourceFieldAttribute? _) in _dataModelService.GetColumnMappings(ResourceType))
5858
{
@@ -64,7 +64,7 @@ public void CaptureNewValues(IIdentifiable resource)
6464

6565
private Dictionary<RelationshipAttribute, ISet<IIdentifiable>> CaptureRightResourcesByRelationship(IIdentifiable resource)
6666
{
67-
Dictionary<RelationshipAttribute, ISet<IIdentifiable>> relationshipValues = new();
67+
Dictionary<RelationshipAttribute, ISet<IIdentifiable>> relationshipValues = [];
6868

6969
foreach (RelationshipAttribute relationship in ResourceType.Relationships)
7070
{
@@ -107,7 +107,7 @@ public void AssertIsNotClearingAnyRequiredToOneRelationships(string resourceName
107107

108108
public IReadOnlyDictionary<HasOneAttribute, (object? currentRightId, object newRightId)> GetOneToOneRelationshipsChangedToNotNull()
109109
{
110-
Dictionary<HasOneAttribute, (object? currentRightId, object newRightId)> changes = new();
110+
Dictionary<HasOneAttribute, (object? currentRightId, object newRightId)> changes = [];
111111

112112
foreach ((RelationshipAttribute relationship, ISet<IIdentifiable> newRightResources) in _newRightResourcesByRelationship)
113113
{
@@ -135,7 +135,7 @@ public void AssertIsNotClearingAnyRequiredToOneRelationships(string resourceName
135135

136136
public IReadOnlyDictionary<string, object?> GetChangedColumnValues()
137137
{
138-
Dictionary<string, object?> changes = new();
138+
Dictionary<string, object?> changes = [];
139139

140140
foreach ((string columnName, object? newColumnValue) in _newColumnValues)
141141
{
@@ -152,7 +152,7 @@ public void AssertIsNotClearingAnyRequiredToOneRelationships(string resourceName
152152

153153
public IReadOnlyDictionary<HasOneAttribute, (object? currentRightId, object? newRightId)> GetChangedToOneRelationshipsWithForeignKeyAtRightSide()
154154
{
155-
Dictionary<HasOneAttribute, (object? currentRightId, object? newRightId)> changes = new();
155+
Dictionary<HasOneAttribute, (object? currentRightId, object? newRightId)> changes = [];
156156

157157
foreach ((RelationshipAttribute relationship, ISet<IIdentifiable> newRightResources) in _newRightResourcesByRelationship)
158158
{
@@ -183,7 +183,7 @@ public void AssertIsNotClearingAnyRequiredToOneRelationships(string resourceName
183183

184184
public IReadOnlyDictionary<HasManyAttribute, (ISet<object> currentRightIds, ISet<object> newRightIds)> GetChangedToManyRelationships()
185185
{
186-
Dictionary<HasManyAttribute, (ISet<object> currentRightIds, ISet<object> newRightIds)> changes = new();
186+
Dictionary<HasManyAttribute, (ISet<object> currentRightIds, ISet<object> newRightIds)> changes = [];
187187

188188
foreach ((RelationshipAttribute relationship, ISet<IIdentifiable> newRightResources) in _newRightResourcesByRelationship)
189189
{
@@ -194,7 +194,7 @@ public void AssertIsNotClearingAnyRequiredToOneRelationships(string resourceName
194194
HashSet<object> currentRightIds =
195195
_currentRightResourcesByRelationship.TryGetValue(hasManyRelationship, out ISet<IIdentifiable>? currentRightResources)
196196
? currentRightResources.Select(resource => resource.GetTypedId()).ToHashSet()
197-
: new HashSet<object>();
197+
: [];
198198

199199
if (!currentRightIds.SetEquals(newRightIds))
200200
{

src/Examples/DapperExample/Repositories/ResultSetMapper.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ namespace DapperExample.Repositories;
1212
internal sealed class ResultSetMapper<TResource, TId>
1313
where TResource : class, IIdentifiable<TId>
1414
{
15-
private readonly List<Type> _joinObjectTypes = new();
15+
private readonly List<Type> _joinObjectTypes = [];
1616

1717
// For each object type, we keep a map of ID/instance pairs.
1818
// Note we don't do full bidirectional relationship fix-up; this just avoids duplicate instances.
19-
private readonly Dictionary<Type, Dictionary<object, object>> _resourceByTypeCache = new();
19+
private readonly Dictionary<Type, Dictionary<object, object>> _resourceByTypeCache = [];
2020

2121
// Optimization to avoid unneeded calls to expensive Activator.CreateInstance() method, which is needed multiple times per row.
22-
private readonly Dictionary<Type, object?> _defaultValueByTypeCache = new();
22+
private readonly Dictionary<Type, object?> _defaultValueByTypeCache = [];
2323

2424
// Used to determine where in the tree of included relationships a join object belongs to.
2525
private readonly Dictionary<IncludeElementExpression, int> _includeElementToJoinObjectArrayIndexLookup = new(ReferenceEqualityComparer.Instance);
2626

2727
// The return value of the mapping process.
28-
private readonly List<TResource> _primaryResourcesInOrder = new();
28+
private readonly List<TResource> _primaryResourcesInOrder = [];
2929

3030
// The included relationships for which an INNER/LEFT JOIN statement was produced, which we're mapping.
3131
private readonly IncludeExpression _include;
@@ -36,15 +36,15 @@ public ResultSetMapper(IncludeExpression? include)
3636
{
3737
_include = include ?? IncludeExpression.Empty;
3838
_joinObjectTypes.Add(typeof(TResource));
39-
_resourceByTypeCache[typeof(TResource)] = new Dictionary<object, object>();
39+
_resourceByTypeCache[typeof(TResource)] = [];
4040

4141
var walker = new IncludeElementWalker(_include);
4242
int index = 1;
4343

4444
foreach (IncludeElementExpression includeElement in walker.BreadthFirstEnumerate())
4545
{
4646
_joinObjectTypes.Add(includeElement.Relationship.RightType.ClrType);
47-
_resourceByTypeCache[includeElement.Relationship.RightType.ClrType] = new Dictionary<object, object>();
47+
_resourceByTypeCache[includeElement.Relationship.RightType.ClrType] = [];
4848
_includeElementToJoinObjectArrayIndexLookup[includeElement] = index;
4949

5050
index++;

src/Examples/DapperExample/Repositories/SqlCaptureStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace DapperExample.Repositories;
99
[PublicAPI]
1010
public sealed class SqlCaptureStore
1111
{
12-
private readonly List<SqlCommand> _sqlCommands = new();
12+
private readonly List<SqlCommand> _sqlCommands = [];
1313

1414
public IReadOnlyList<SqlCommand> SqlCommands => _sqlCommands;
1515

src/Examples/DapperExample/TranslationToSql/Builders/InsertStatementBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public InsertNode Build(ResourceType resourceType, IReadOnlyDictionary<string, o
2828

2929
private List<ColumnAssignmentNode> GetColumnAssignments(IReadOnlyDictionary<string, object?> columnsToSet, TableNode table)
3030
{
31-
List<ColumnAssignmentNode> assignments = new();
31+
List<ColumnAssignmentNode> assignments = [];
3232
ColumnNode idColumn = table.GetIdColumn(table.Alias);
3333

3434
foreach ((string columnName, object? columnValue) in columnsToSet)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy