@@ -125,21 +125,21 @@ private IncludeExpression ComposeChildren(QueryLayer topLayer, ICollection<Expre
125
125
// @formatter:keep_existing_linebreaks restore
126
126
// @formatter:wrap_chained_method_calls restore
127
127
128
- IReadOnlyCollection < IncludeElementExpression > includeElements =
128
+ IImmutableList < IncludeElementExpression > includeElements =
129
129
ProcessIncludeSet ( include . Elements , topLayer , new List < RelationshipAttribute > ( ) , constraints ) ;
130
130
131
131
return ! ReferenceEquals ( includeElements , include . Elements )
132
132
? includeElements . Any ( ) ? new IncludeExpression ( includeElements ) : IncludeExpression . Empty
133
133
: include ;
134
134
}
135
135
136
- private IReadOnlyCollection < IncludeElementExpression > ProcessIncludeSet ( IReadOnlyCollection < IncludeElementExpression > includeElements ,
137
- QueryLayer parentLayer , ICollection < RelationshipAttribute > parentRelationshipChain , ICollection < ExpressionInScope > constraints )
136
+ private IImmutableList < IncludeElementExpression > ProcessIncludeSet ( IImmutableList < IncludeElementExpression > includeElements , QueryLayer parentLayer ,
137
+ ICollection < RelationshipAttribute > parentRelationshipChain , ICollection < ExpressionInScope > constraints )
138
138
{
139
- IReadOnlyCollection < IncludeElementExpression > includeElementsEvaluated =
140
- GetIncludeElements ( includeElements , parentLayer . ResourceContext ) ?? Array . Empty < IncludeElementExpression > ( ) ;
139
+ IImmutableList < IncludeElementExpression > includeElementsEvaluated =
140
+ GetIncludeElements ( includeElements , parentLayer . ResourceContext ) ?? ImmutableArray < IncludeElementExpression > . Empty ;
141
141
142
- var updatesInChildren = new Dictionary < IncludeElementExpression , IReadOnlyCollection < IncludeElementExpression > > ( ) ;
142
+ var updatesInChildren = new Dictionary < IncludeElementExpression , IImmutableList < IncludeElementExpression > > ( ) ;
143
143
144
144
foreach ( IncludeElementExpression includeElement in includeElementsEvaluated )
145
145
{
@@ -181,7 +181,7 @@ private IReadOnlyCollection<IncludeElementExpression> ProcessIncludeSet(IReadOnl
181
181
182
182
if ( includeElement . Children . Any ( ) )
183
183
{
184
- IReadOnlyCollection < IncludeElementExpression > updatedChildren =
184
+ IImmutableList < IncludeElementExpression > updatedChildren =
185
185
ProcessIncludeSet ( includeElement . Children , child , relationshipChain , constraints ) ;
186
186
187
187
if ( ! ReferenceEquals ( includeElement . Children , updatedChildren ) )
@@ -195,18 +195,19 @@ private IReadOnlyCollection<IncludeElementExpression> ProcessIncludeSet(IReadOnl
195
195
return ! updatesInChildren . Any ( ) ? includeElementsEvaluated : ApplyIncludeElementUpdates ( includeElementsEvaluated , updatesInChildren ) ;
196
196
}
197
197
198
- private static IReadOnlyCollection < IncludeElementExpression > ApplyIncludeElementUpdates ( IEnumerable < IncludeElementExpression > includeElements ,
199
- IDictionary < IncludeElementExpression , IReadOnlyCollection < IncludeElementExpression > > updatesInChildren )
198
+ private static IImmutableList < IncludeElementExpression > ApplyIncludeElementUpdates ( IImmutableList < IncludeElementExpression > includeElements ,
199
+ IDictionary < IncludeElementExpression , IImmutableList < IncludeElementExpression > > updatesInChildren )
200
200
{
201
- List < IncludeElementExpression > newIncludeElements = includeElements . ToList ( ) ;
201
+ ImmutableArray < IncludeElementExpression > . Builder newElementsBuilder = ImmutableArray . CreateBuilder < IncludeElementExpression > ( includeElements . Count ) ;
202
+ newElementsBuilder . AddRange ( includeElements ) ;
202
203
203
- foreach ( ( IncludeElementExpression existingElement , IReadOnlyCollection < IncludeElementExpression > updatedChildren ) in updatesInChildren )
204
+ foreach ( ( IncludeElementExpression existingElement , IImmutableList < IncludeElementExpression > updatedChildren ) in updatesInChildren )
204
205
{
205
- int existingIndex = newIncludeElements . IndexOf ( existingElement ) ;
206
- newIncludeElements [ existingIndex ] = new IncludeElementExpression ( existingElement . Relationship , updatedChildren ) ;
206
+ int existingIndex = newElementsBuilder . IndexOf ( existingElement ) ;
207
+ newElementsBuilder [ existingIndex ] = new IncludeElementExpression ( existingElement . Relationship , updatedChildren ) ;
207
208
}
208
209
209
- return newIncludeElements ;
210
+ return newElementsBuilder . ToImmutable ( ) ;
210
211
}
211
212
212
213
/// <inheritdoc />
@@ -294,7 +295,7 @@ private IncludeExpression RewriteIncludeForSecondaryEndpoint(IncludeExpression r
294
295
? new IncludeElementExpression ( secondaryRelationship , relativeInclude . Elements )
295
296
: new IncludeElementExpression ( secondaryRelationship ) ;
296
297
297
- return new IncludeExpression ( parentElement . AsArray ( ) ) ;
298
+ return new IncludeExpression ( ImmutableArray . Create ( parentElement ) ) ;
298
299
}
299
300
300
301
private FilterExpression CreateFilterByIds < TId > ( IReadOnlyCollection < TId > ids , AttrAttribute idAttribute , FilterExpression existingFilter )
@@ -310,7 +311,7 @@ private FilterExpression CreateFilterByIds<TId>(IReadOnlyCollection<TId> ids, At
310
311
}
311
312
else if ( ids . Count > 1 )
312
313
{
313
- IImmutableSet < LiteralConstantExpression > constants = ids . Select ( id => new LiteralConstantExpression ( id . ToString ( ) ) ) . ToImmutableHashSet ( ) ;
314
+ ImmutableHashSet < LiteralConstantExpression > constants = ids . Select ( id => new LiteralConstantExpression ( id . ToString ( ) ) ) . ToImmutableHashSet ( ) ;
314
315
filter = new AnyExpression ( idChain , constants ) ;
315
316
}
316
317
@@ -322,8 +323,8 @@ public QueryLayer ComposeForUpdate<TId>(TId id, ResourceContext primaryResource)
322
323
{
323
324
ArgumentGuard . NotNull ( primaryResource , nameof ( primaryResource ) ) ;
324
325
325
- IncludeElementExpression [ ] includeElements = _targetedFields . Relationships
326
- . Select ( relationship => new IncludeElementExpression ( relationship ) ) . ToArray ( ) ;
326
+ ImmutableArray < IncludeElementExpression > includeElements = _targetedFields . Relationships
327
+ . Select ( relationship => new IncludeElementExpression ( relationship ) ) . ToImmutableArray ( ) ;
327
328
328
329
AttrAttribute primaryIdAttribute = GetIdAttribute ( primaryResource ) ;
329
330
@@ -398,7 +399,7 @@ public QueryLayer ComposeForHasMany<TId>(HasManyAttribute hasManyRelationship, T
398
399
399
400
return new QueryLayer ( leftResourceContext )
400
401
{
401
- Include = new IncludeExpression ( new IncludeElementExpression ( hasManyRelationship ) . AsArray ( ) ) ,
402
+ Include = new IncludeExpression ( ImmutableArray . Create ( new IncludeElementExpression ( hasManyRelationship ) ) ) ,
402
403
Filter = leftFilter ,
403
404
Projection = new Dictionary < ResourceFieldAttribute , QueryLayer >
404
405
{
@@ -421,7 +422,7 @@ public IResourceDefinitionAccessor GetResourceDefinitionAccessor()
421
422
return _resourceDefinitionAccessor ;
422
423
}
423
424
424
- protected virtual IReadOnlyCollection < IncludeElementExpression > GetIncludeElements ( IReadOnlyCollection < IncludeElementExpression > includeElements ,
425
+ protected virtual IImmutableList < IncludeElementExpression > GetIncludeElements ( IImmutableList < IncludeElementExpression > includeElements ,
425
426
ResourceContext resourceContext )
426
427
{
427
428
ArgumentGuard . NotNull ( resourceContext , nameof ( resourceContext ) ) ;
@@ -434,8 +435,8 @@ protected virtual FilterExpression GetFilter(IReadOnlyCollection<QueryExpression
434
435
ArgumentGuard . NotNull ( expressionsInScope , nameof ( expressionsInScope ) ) ;
435
436
ArgumentGuard . NotNull ( resourceContext , nameof ( resourceContext ) ) ;
436
437
437
- IImmutableList < FilterExpression > filters = expressionsInScope . OfType < FilterExpression > ( ) . ToImmutableArray ( ) ;
438
- FilterExpression filter = filters . Count > 1 ? new LogicalExpression ( LogicalOperator . And , filters ) : filters . FirstOrDefault ( ) ;
438
+ ImmutableArray < FilterExpression > filters = expressionsInScope . OfType < FilterExpression > ( ) . ToImmutableArray ( ) ;
439
+ FilterExpression filter = filters . Length > 1 ? new LogicalExpression ( LogicalOperator . And , filters ) : filters . FirstOrDefault ( ) ;
439
440
440
441
return _resourceDefinitionAccessor . OnApplyFilter ( resourceContext . ResourceType , filter ) ;
441
442
}
0 commit comments