@@ -29,17 +29,16 @@ public IncludeExpression Parse(string source, ResourceType resourceType)
29
29
30
30
Tokenize ( source ) ;
31
31
32
- IncludeExpression expression = ParseInclude ( source , resourceType ) ;
32
+ IncludeExpression expression = ParseInclude ( resourceType ) ;
33
33
34
34
AssertTokenStackIsEmpty ( ) ;
35
35
ValidateMaximumIncludeDepth ( expression , 0 ) ;
36
36
37
37
return expression ;
38
38
}
39
39
40
- protected virtual IncludeExpression ParseInclude ( string source , ResourceType resourceType )
40
+ protected virtual IncludeExpression ParseInclude ( ResourceType resourceType )
41
41
{
42
- ArgumentNullException . ThrowIfNull ( source ) ;
43
42
ArgumentNullException . ThrowIfNull ( resourceType ) ;
44
43
45
44
var treeRoot = IncludeTreeNode . CreateRoot ( resourceType ) ;
@@ -56,13 +55,13 @@ protected virtual IncludeExpression ParseInclude(string source, ResourceType res
56
55
isAtStart = false ;
57
56
}
58
57
59
- ParseRelationshipChain ( source , treeRoot ) ;
58
+ ParseRelationshipChain ( treeRoot ) ;
60
59
}
61
60
62
61
return treeRoot . ToExpression ( ) ;
63
62
}
64
63
65
- private void ParseRelationshipChain ( string source , IncludeTreeNode treeRoot )
64
+ private void ParseRelationshipChain ( IncludeTreeNode treeRoot )
66
65
{
67
66
// A relationship name usually matches a single relationship, even when overridden in derived types.
68
67
// But in the following case, two relationships are matched on GET /shoppingBaskets?include=items:
@@ -90,30 +89,29 @@ private void ParseRelationshipChain(string source, IncludeTreeNode treeRoot)
90
89
// that there's currently no way to include Products without Articles. We could add such optional upcast syntax
91
90
// in the future, if desired.
92
91
93
- ReadOnlyCollection < IncludeTreeNode > children = ParseRelationshipName ( source , [ treeRoot ] ) ;
92
+ ReadOnlyCollection < IncludeTreeNode > children = ParseRelationshipName ( [ treeRoot ] ) ;
94
93
95
94
while ( TokenStack . TryPeek ( out Token ? nextToken ) && nextToken . Kind == TokenKind . Period )
96
95
{
97
96
EatSingleCharacterToken ( TokenKind . Period ) ;
98
97
99
- children = ParseRelationshipName ( source , children ) ;
98
+ children = ParseRelationshipName ( children ) ;
100
99
}
101
100
}
102
101
103
- private ReadOnlyCollection < IncludeTreeNode > ParseRelationshipName ( string source , IReadOnlyCollection < IncludeTreeNode > parents )
102
+ private ReadOnlyCollection < IncludeTreeNode > ParseRelationshipName ( IReadOnlyCollection < IncludeTreeNode > parents )
104
103
{
105
104
int position = GetNextTokenPositionOrEnd ( ) ;
106
105
107
106
if ( TokenStack . TryPop ( out Token ? token ) && token . Kind == TokenKind . Text )
108
107
{
109
- return LookupRelationshipName ( token . Value ! , parents , source , position ) ;
108
+ return LookupRelationshipName ( token . Value ! , parents , position ) ;
110
109
}
111
110
112
111
throw new QueryParseException ( "Relationship name expected." , position ) ;
113
112
}
114
113
115
- private static ReadOnlyCollection < IncludeTreeNode > LookupRelationshipName ( string relationshipName , IReadOnlyCollection < IncludeTreeNode > parents ,
116
- string source , int position )
114
+ private ReadOnlyCollection < IncludeTreeNode > LookupRelationshipName ( string relationshipName , IReadOnlyCollection < IncludeTreeNode > parents , int position )
117
115
{
118
116
List < IncludeTreeNode > children = [ ] ;
119
117
HashSet < RelationshipAttribute > relationshipsFound = [ ] ;
@@ -135,7 +133,7 @@ private static ReadOnlyCollection<IncludeTreeNode> LookupRelationshipName(string
135
133
}
136
134
137
135
AssertRelationshipsFound ( relationshipsFound , relationshipName , parents , position ) ;
138
- AssertAtLeastOneCanBeIncluded ( relationshipsFound , relationshipName , source , position ) ;
136
+ AssertAtLeastOneCanBeIncluded ( relationshipsFound , relationshipName , position ) ;
139
137
140
138
return children . AsReadOnly ( ) ;
141
139
}
@@ -201,15 +199,15 @@ private static string GetErrorMessageForNoneFound(string relationshipName, Resou
201
199
return builder . ToString ( ) ;
202
200
}
203
201
204
- private static void AssertAtLeastOneCanBeIncluded ( HashSet < RelationshipAttribute > relationshipsFound , string relationshipName , string source , int position )
202
+ private void AssertAtLeastOneCanBeIncluded ( HashSet < RelationshipAttribute > relationshipsFound , string relationshipName , int position )
205
203
{
206
204
if ( relationshipsFound . All ( relationship => relationship . IsIncludeBlocked ( ) ) )
207
205
{
208
206
ResourceType resourceType = relationshipsFound . First ( ) . LeftType ;
209
207
string message = $ "Including the relationship '{ relationshipName } ' on '{ resourceType } ' is not allowed.";
210
208
211
209
var exception = new QueryParseException ( message , position ) ;
212
- string specificMessage = exception . GetMessageWithPosition ( source ) ;
210
+ string specificMessage = exception . GetMessageWithPosition ( Source ) ;
213
211
214
212
throw new InvalidQueryStringParameterException ( "include" , "The specified include is invalid." , specificMessage ) ;
215
213
}
0 commit comments