@@ -186,6 +186,7 @@ private bool TryHandleGetRawPagesAsyncMethod(MethodProvider method)
186186 // This is to ensure that pagination stops when hasMore is false, in addition to checking LastId.
187187 if ( ( method . Signature . Name == "GetRawPagesAsync" || method . Signature . Name == "GetRawPages" ) && method . EnclosingType . DeclarationModifiers . HasFlag ( TypeSignatureModifiers . Internal ) )
188188 {
189+ VariableExpression ? hasMoreVariable = null ;
189190 var statements = method . BodyStatements ? . ToList ( ) ?? new List < MethodBodyStatement > ( ) ;
190191 VisitExplodedMethodBodyStatements (
191192 statements ! ,
@@ -206,11 +207,9 @@ private bool TryHandleGetRawPagesAsyncMethod(MethodProvider method)
206207 binaryExpr . Right is KeywordExpression rightKeyword &&
207208 rightKeyword . Keyword == "null" )
208209 {
209- // Create "!hasMore" condition
210- var hasMoreNullCheck = new UnaryOperatorExpression (
211- "!" ,
212- new MemberExpression ( null , "hasMore" ) ,
213- OperandOnTheLeft : false ) ;
210+ // Create "!hasMore" condition. Note the hasMoreVariable gets assigned earlier in the method statements
211+ // in the WhileStatement handler below.
212+ var hasMoreNullCheck = Snippet . Not ( hasMoreVariable ) ;
214213
215214 // Return "nextToken == null || !hasMore"
216215 return new BinaryOperatorExpression ( "||" , binaryExpr , hasMoreNullCheck ) ;
@@ -238,7 +237,7 @@ assignmentExpression.Value is MemberExpression memberExpression &&
238237 {
239238 // Create a new assignment for hasMore
240239 var hasMoreAssignment = new AssignmentExpression (
241- new DeclarationExpression ( typeof ( bool ) , "hasMore" ) ,
240+ Snippet . Declare ( "hasMore" , typeof ( bool ) , out hasMoreVariable ) ,
242241 new MemberExpression ( memberExpression . Inner , "HasMore" ) ) ;
243242
244243 // Insert the new assignment before the existing one
0 commit comments