@@ -125,21 +125,21 @@ private IncludeExpression ComposeChildren(QueryLayer topLayer, ICollection<Expre
125125 // @formatter:keep_existing_linebreaks restore
126126 // @formatter:wrap_chained_method_calls restore
127127
128- IReadOnlyCollection < IncludeElementExpression > includeElements =
128+ IImmutableList < IncludeElementExpression > includeElements =
129129 ProcessIncludeSet ( include . Elements , topLayer , new List < RelationshipAttribute > ( ) , constraints ) ;
130130
131131 return ! ReferenceEquals ( includeElements , include . Elements )
132132 ? includeElements . Any ( ) ? new IncludeExpression ( includeElements ) : IncludeExpression . Empty
133133 : include ;
134134 }
135135
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 )
138138 {
139- IReadOnlyCollection < IncludeElementExpression > includeElementsEvaluated =
140- GetIncludeElements ( includeElements , parentLayer . ResourceContext ) ?? Array . Empty < IncludeElementExpression > ( ) ;
139+ IImmutableList < IncludeElementExpression > includeElementsEvaluated =
140+ GetIncludeElements ( includeElements , parentLayer . ResourceContext ) ?? ImmutableArray < IncludeElementExpression > . Empty ;
141141
142- var updatesInChildren = new Dictionary < IncludeElementExpression , IReadOnlyCollection < IncludeElementExpression > > ( ) ;
142+ var updatesInChildren = new Dictionary < IncludeElementExpression , IImmutableList < IncludeElementExpression > > ( ) ;
143143
144144 foreach ( IncludeElementExpression includeElement in includeElementsEvaluated )
145145 {
@@ -181,7 +181,7 @@ private IReadOnlyCollection<IncludeElementExpression> ProcessIncludeSet(IReadOnl
181181
182182 if ( includeElement . Children . Any ( ) )
183183 {
184- IReadOnlyCollection < IncludeElementExpression > updatedChildren =
184+ IImmutableList < IncludeElementExpression > updatedChildren =
185185 ProcessIncludeSet ( includeElement . Children , child , relationshipChain , constraints ) ;
186186
187187 if ( ! ReferenceEquals ( includeElement . Children , updatedChildren ) )
@@ -195,18 +195,19 @@ private IReadOnlyCollection<IncludeElementExpression> ProcessIncludeSet(IReadOnl
195195 return ! updatesInChildren . Any ( ) ? includeElementsEvaluated : ApplyIncludeElementUpdates ( includeElementsEvaluated , updatesInChildren ) ;
196196 }
197197
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 )
200200 {
201- List < IncludeElementExpression > newIncludeElements = includeElements . ToList ( ) ;
201+ ImmutableArray < IncludeElementExpression > . Builder newElementsBuilder = ImmutableArray . CreateBuilder < IncludeElementExpression > ( includeElements . Count ) ;
202+ newElementsBuilder . AddRange ( includeElements ) ;
202203
203- foreach ( ( IncludeElementExpression existingElement , IReadOnlyCollection < IncludeElementExpression > updatedChildren ) in updatesInChildren )
204+ foreach ( ( IncludeElementExpression existingElement , IImmutableList < IncludeElementExpression > updatedChildren ) in updatesInChildren )
204205 {
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 ) ;
207208 }
208209
209- return newIncludeElements ;
210+ return newElementsBuilder . ToImmutable ( ) ;
210211 }
211212
212213 /// <inheritdoc />
@@ -294,7 +295,7 @@ private IncludeExpression RewriteIncludeForSecondaryEndpoint(IncludeExpression r
294295 ? new IncludeElementExpression ( secondaryRelationship , relativeInclude . Elements )
295296 : new IncludeElementExpression ( secondaryRelationship ) ;
296297
297- return new IncludeExpression ( parentElement . AsArray ( ) ) ;
298+ return new IncludeExpression ( ImmutableArray . Create ( parentElement ) ) ;
298299 }
299300
300301 private FilterExpression CreateFilterByIds < TId > ( IReadOnlyCollection < TId > ids , AttrAttribute idAttribute , FilterExpression existingFilter )
@@ -310,7 +311,7 @@ private FilterExpression CreateFilterByIds<TId>(IReadOnlyCollection<TId> ids, At
310311 }
311312 else if ( ids . Count > 1 )
312313 {
313- IImmutableSet < LiteralConstantExpression > constants = ids . Select ( id => new LiteralConstantExpression ( id . ToString ( ) ) ) . ToImmutableHashSet ( ) ;
314+ ImmutableHashSet < LiteralConstantExpression > constants = ids . Select ( id => new LiteralConstantExpression ( id . ToString ( ) ) ) . ToImmutableHashSet ( ) ;
314315 filter = new AnyExpression ( idChain , constants ) ;
315316 }
316317
@@ -322,8 +323,8 @@ public QueryLayer ComposeForUpdate<TId>(TId id, ResourceContext primaryResource)
322323 {
323324 ArgumentGuard . NotNull ( primaryResource , nameof ( primaryResource ) ) ;
324325
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 ( ) ;
327328
328329 AttrAttribute primaryIdAttribute = GetIdAttribute ( primaryResource ) ;
329330
@@ -398,7 +399,7 @@ public QueryLayer ComposeForHasMany<TId>(HasManyAttribute hasManyRelationship, T
398399
399400 return new QueryLayer ( leftResourceContext )
400401 {
401- Include = new IncludeExpression ( new IncludeElementExpression ( hasManyRelationship ) . AsArray ( ) ) ,
402+ Include = new IncludeExpression ( ImmutableArray . Create ( new IncludeElementExpression ( hasManyRelationship ) ) ) ,
402403 Filter = leftFilter ,
403404 Projection = new Dictionary < ResourceFieldAttribute , QueryLayer >
404405 {
@@ -421,7 +422,7 @@ public IResourceDefinitionAccessor GetResourceDefinitionAccessor()
421422 return _resourceDefinitionAccessor ;
422423 }
423424
424- protected virtual IReadOnlyCollection < IncludeElementExpression > GetIncludeElements ( IReadOnlyCollection < IncludeElementExpression > includeElements ,
425+ protected virtual IImmutableList < IncludeElementExpression > GetIncludeElements ( IImmutableList < IncludeElementExpression > includeElements ,
425426 ResourceContext resourceContext )
426427 {
427428 ArgumentGuard . NotNull ( resourceContext , nameof ( resourceContext ) ) ;
@@ -434,8 +435,8 @@ protected virtual FilterExpression GetFilter(IReadOnlyCollection<QueryExpression
434435 ArgumentGuard . NotNull ( expressionsInScope , nameof ( expressionsInScope ) ) ;
435436 ArgumentGuard . NotNull ( resourceContext , nameof ( resourceContext ) ) ;
436437
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 ( ) ;
439440
440441 return _resourceDefinitionAccessor . OnApplyFilter ( resourceContext . ResourceType , filter ) ;
441442 }
0 commit comments