From 8751131b152af09de8bd2640a045d2ef2da32011 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Mon, 17 Nov 2025 13:01:12 +0000 Subject: [PATCH 1/3] feat: use await foreach instead of AsyncEnumerable.ForEachAsync This allows us to remove the dependency on System.Linq.Async entirely. Test changes are in the next commit. Towards https://github.com/googleapis/google-cloud-dotnet/issues/15037 --- Directory.Packages.props | 1 - Google.Api.Generator.Utils/Roslyn/RoslynBuilder.cs | 3 +++ Google.Api.Generator/Generation/CsProjGenerator.cs | 2 -- Google.Api.Generator/Generation/SnippetCodeGenerator.cs | 8 ++++---- Google.Api.Generator/Google.Api.Generator.csproj | 1 - 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index b8a4d3f0..d55981ab 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -24,7 +24,6 @@ - diff --git a/Google.Api.Generator.Utils/Roslyn/RoslynBuilder.cs b/Google.Api.Generator.Utils/Roslyn/RoslynBuilder.cs index 233bb30d..72a373ab 100644 --- a/Google.Api.Generator.Utils/Roslyn/RoslynBuilder.cs +++ b/Google.Api.Generator.Utils/Roslyn/RoslynBuilder.cs @@ -240,6 +240,9 @@ public static ArgumentsFunc NewArray(ArrayTypeSyn public static ArrayCreationExpressionSyntax NewArray(ArrayTypeSyntax arrayType, ExpressionSyntax rank) => ArrayCreationExpression(arrayType.WithRankSpecifiers(SingletonList(ArrayRankSpecifier(SingletonSeparatedList(rank))))); + public static CodeFunc AwaitForEach(TypeSyntax type, SyntaxToken varName, object expr) => code => + ForEachStatement(type, varName, ToExpression(expr), Block(ToStatements(code))).WithLeadingSpace().WithAwaitKeyword(Token(SyntaxKind.AwaitKeyword)); + public static CodeFunc ForEach(TypeSyntax type, SyntaxToken varName, object expr) => code => ForEachStatement(type, varName, ToExpression(expr), Block(ToStatements(code))); diff --git a/Google.Api.Generator/Generation/CsProjGenerator.cs b/Google.Api.Generator/Generation/CsProjGenerator.cs index c40fb996..2e55d4e5 100644 --- a/Google.Api.Generator/Generation/CsProjGenerator.cs +++ b/Google.Api.Generator/Generation/CsProjGenerator.cs @@ -29,7 +29,6 @@ internal static class CsProjGenerator private const string IamVersion = "[3.5.0, 4.0.0)"; private const string LocationVersion = "[2.4.0, 3.0.0)"; private const string ReferenceAssembliesVersion = "1.0.3"; - private const string SystemLinqAsyncVersion = "6.0.3"; private static readonly Dictionary ProtoPackageToNuGetPackageAndVersion = new Dictionary { { IamPolicyReflection.Descriptor.Package, (typeof(IAMPolicyClient).Namespace, IamVersion) }, @@ -120,7 +119,6 @@ public static string GenerateSnippets(string clientNamespace) - diff --git a/Google.Api.Generator/Generation/SnippetCodeGenerator.cs b/Google.Api.Generator/Generation/SnippetCodeGenerator.cs index 1b2ff6ca..e5d326b3 100644 --- a/Google.Api.Generator/Generation/SnippetCodeGenerator.cs +++ b/Google.Api.Generator/Generation/SnippetCodeGenerator.cs @@ -615,18 +615,18 @@ private MethodDeclarationSyntax AsyncPaginated(string methodName, IEnumerable.AsRawResponses))().Call(nameof(AsyncEnumerable.ForEachAsync))(LambdaTyped(PaginatedPage)( + AwaitForEach(Ctx.Type(Method.ResponseTyp), PaginatedPage.Identifier, AsyncResponse.Call(nameof(PagedEnumerable.AsRawResponses))())( "// Do something with each page of items", Ctx.Type(typeof(Console)).Call(nameof(Console.WriteLine))("A page of results:"), ForEach(Ctx.Type(MethodPaginated.ResourceTyp), PaginatedItem.Identifier, PaginatedPage)( "// Do something with each item", Ctx.Type(typeof(Console)).Call(nameof(Console.WriteLine))(PaginatedItem)) - ))), + ), BlankLine, "// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required", PageSize.WithInitializer(10), diff --git a/Google.Api.Generator/Google.Api.Generator.csproj b/Google.Api.Generator/Google.Api.Generator.csproj index d0d37119..da34d60a 100644 --- a/Google.Api.Generator/Google.Api.Generator.csproj +++ b/Google.Api.Generator/Google.Api.Generator.csproj @@ -20,7 +20,6 @@ - From 5caa5805345a9eaf2e1cfdaa1c4751f97be03b1d Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Mon, 17 Nov 2025 13:01:58 +0000 Subject: [PATCH 2/3] tests: test changes for using await foreach (Other changes are just in terms of the BOM.) --- .../Testing.Basic.V1.GeneratedSnippets.csproj | 1 - .../Testing.Basic.V1.Snippets.csproj | 1 - ...edClient.ResourcedMethod1AsyncSnippet.g.cs | 11 ++- ...urcedMethod1ResourceNamesAsyncSnippet.g.cs | 11 ++- ....ResourcedMethod1ResourceNamesSnippet.g.cs | 2 +- ...ginatedClient.ResourcedMethod1Snippet.g.cs | 2 +- ...edClient.ResourcedMethod2AsyncSnippet.g.cs | 11 ++- ...urcedMethod2ResourceNamesAsyncSnippet.g.cs | 11 ++- ....ResourcedMethod2ResourceNamesSnippet.g.cs | 2 +- ...ginatedClient.ResourcedMethod2Snippet.g.cs | 2 +- ...ourcedMethodRequestObjectAsyncSnippet.g.cs | 11 ++- ...t.ResourcedMethodRequestObjectSnippet.g.cs | 2 +- ...edClient.SignatureMethod1AsyncSnippet.g.cs | 11 ++- ...ginatedClient.SignatureMethod1Snippet.g.cs | 2 +- ...edClient.SignatureMethod2AsyncSnippet.g.cs | 11 ++- ...atureMethod2RequestObjectAsyncSnippet.g.cs | 11 ++- ....SignatureMethod2RequestObjectSnippet.g.cs | 2 +- ...ginatedClient.SignatureMethod2Snippet.g.cs | 2 +- ...edClient.SignatureMethod3AsyncSnippet.g.cs | 11 ++- ...ginatedClient.SignatureMethod3Snippet.g.cs | 2 +- ...natureMethodRequestObjectAsyncSnippet.g.cs | 11 ++- ...t.SignatureMethodRequestObjectSnippet.g.cs | 2 +- .../snippet_metadata_testing.paginated.json | 62 +++++++------- .../PaginatedClientSnippets.g.cs | 83 +++++++++---------- ...utoPopulatedRequestObjectAsyncSnippet.g.cs | 9 +- ...t_metadata_testing.publishingsettings.json | 6 +- ...rviceWithMethodSettingsClientSnippets.g.cs | 9 +- 27 files changed, 143 insertions(+), 158 deletions(-) diff --git a/Google.Api.Generator.Tests/ProtoTests/Basic.v1/Testing.Basic.V1.GeneratedSnippets/Testing.Basic.V1.GeneratedSnippets.csproj b/Google.Api.Generator.Tests/ProtoTests/Basic.v1/Testing.Basic.V1.GeneratedSnippets/Testing.Basic.V1.GeneratedSnippets.csproj index aae34042..c634c890 100644 --- a/Google.Api.Generator.Tests/ProtoTests/Basic.v1/Testing.Basic.V1.GeneratedSnippets/Testing.Basic.V1.GeneratedSnippets.csproj +++ b/Google.Api.Generator.Tests/ProtoTests/Basic.v1/Testing.Basic.V1.GeneratedSnippets/Testing.Basic.V1.GeneratedSnippets.csproj @@ -8,7 +8,6 @@ - diff --git a/Google.Api.Generator.Tests/ProtoTests/Basic.v1/Testing.Basic.V1.Snippets/Testing.Basic.V1.Snippets.csproj b/Google.Api.Generator.Tests/ProtoTests/Basic.v1/Testing.Basic.V1.Snippets/Testing.Basic.V1.Snippets.csproj index aae34042..c634c890 100644 --- a/Google.Api.Generator.Tests/ProtoTests/Basic.v1/Testing.Basic.V1.Snippets/Testing.Basic.V1.Snippets.csproj +++ b/Google.Api.Generator.Tests/ProtoTests/Basic.v1/Testing.Basic.V1.Snippets/Testing.Basic.V1.Snippets.csproj @@ -8,7 +8,6 @@ - diff --git a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod1AsyncSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod1AsyncSnippet.g.cs index 52c59187..41107be6 100644 --- a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod1AsyncSnippet.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod1AsyncSnippet.g.cs @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC +// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ namespace GoogleCSharpSnippets // [START paginated_generated_Paginated_ResourcedMethod_async_flattened1] using Google.Api.Gax; using System; - using System.Linq; using System.Threading.Tasks; using Testing.Paginated; @@ -43,14 +42,14 @@ public async Task ResourcedMethod1Async() PagedAsyncEnumerable response = paginatedClient.ResourcedMethodAsync(name); // Iterate over all response items, lazily performing RPCs as required - await response.ForEachAsync((string item) => + await foreach (string item in response) { // Do something with each item Console.WriteLine(item); - }); + } // Or iterate over pages (of server-defined size), performing one RPC per page - await response.AsRawResponses().ForEachAsync((ResourceResponse page) => + await foreach (ResourceResponse page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); @@ -59,7 +58,7 @@ await response.AsRawResponses().ForEachAsync((ResourceResponse page) => // Do something with each item Console.WriteLine(item); } - }); + } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; diff --git a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod1ResourceNamesAsyncSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod1ResourceNamesAsyncSnippet.g.cs index 1a89e0a3..61832eee 100644 --- a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod1ResourceNamesAsyncSnippet.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod1ResourceNamesAsyncSnippet.g.cs @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC +// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ namespace GoogleCSharpSnippets // [START paginated_generated_Paginated_ResourcedMethod_async_flattened1_resourceNames] using Google.Api.Gax; using System; - using System.Linq; using System.Threading.Tasks; using Testing.Paginated; @@ -43,14 +42,14 @@ public async Task ResourcedMethod1ResourceNamesAsync() PagedAsyncEnumerable response = paginatedClient.ResourcedMethodAsync(name); // Iterate over all response items, lazily performing RPCs as required - await response.ForEachAsync((string item) => + await foreach (string item in response) { // Do something with each item Console.WriteLine(item); - }); + } // Or iterate over pages (of server-defined size), performing one RPC per page - await response.AsRawResponses().ForEachAsync((ResourceResponse page) => + await foreach (ResourceResponse page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); @@ -59,7 +58,7 @@ await response.AsRawResponses().ForEachAsync((ResourceResponse page) => // Do something with each item Console.WriteLine(item); } - }); + } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; diff --git a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod1ResourceNamesSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod1ResourceNamesSnippet.g.cs index 4b3061cd..c278aae9 100644 --- a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod1ResourceNamesSnippet.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod1ResourceNamesSnippet.g.cs @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC +// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod1Snippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod1Snippet.g.cs index d723b7e5..e648554d 100644 --- a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod1Snippet.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod1Snippet.g.cs @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC +// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod2AsyncSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod2AsyncSnippet.g.cs index 5a685057..ec0a1ab5 100644 --- a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod2AsyncSnippet.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod2AsyncSnippet.g.cs @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC +// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ namespace GoogleCSharpSnippets // [START paginated_generated_Paginated_ResourcedMethod_async_flattened2] using Google.Api.Gax; using System; - using System.Linq; using System.Threading.Tasks; using Testing.Paginated; @@ -44,14 +43,14 @@ public async Task ResourcedMethod2Async() PagedAsyncEnumerable response = paginatedClient.ResourcedMethodAsync(name, extraString: extraString); // Iterate over all response items, lazily performing RPCs as required - await response.ForEachAsync((string item) => + await foreach (string item in response) { // Do something with each item Console.WriteLine(item); - }); + } // Or iterate over pages (of server-defined size), performing one RPC per page - await response.AsRawResponses().ForEachAsync((ResourceResponse page) => + await foreach (ResourceResponse page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); @@ -60,7 +59,7 @@ await response.AsRawResponses().ForEachAsync((ResourceResponse page) => // Do something with each item Console.WriteLine(item); } - }); + } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; diff --git a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod2ResourceNamesAsyncSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod2ResourceNamesAsyncSnippet.g.cs index 6ef0d4d1..6d00bdb0 100644 --- a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod2ResourceNamesAsyncSnippet.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod2ResourceNamesAsyncSnippet.g.cs @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC +// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ namespace GoogleCSharpSnippets // [START paginated_generated_Paginated_ResourcedMethod_async_flattened2_resourceNames] using Google.Api.Gax; using System; - using System.Linq; using System.Threading.Tasks; using Testing.Paginated; @@ -44,14 +43,14 @@ public async Task ResourcedMethod2ResourceNamesAsync() PagedAsyncEnumerable response = paginatedClient.ResourcedMethodAsync(name, extraString: extraString); // Iterate over all response items, lazily performing RPCs as required - await response.ForEachAsync((string item) => + await foreach (string item in response) { // Do something with each item Console.WriteLine(item); - }); + } // Or iterate over pages (of server-defined size), performing one RPC per page - await response.AsRawResponses().ForEachAsync((ResourceResponse page) => + await foreach (ResourceResponse page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); @@ -60,7 +59,7 @@ await response.AsRawResponses().ForEachAsync((ResourceResponse page) => // Do something with each item Console.WriteLine(item); } - }); + } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; diff --git a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod2ResourceNamesSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod2ResourceNamesSnippet.g.cs index 9190771d..35c614ee 100644 --- a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod2ResourceNamesSnippet.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod2ResourceNamesSnippet.g.cs @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC +// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod2Snippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod2Snippet.g.cs index 53252ad9..156d63d8 100644 --- a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod2Snippet.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethod2Snippet.g.cs @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC +// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethodRequestObjectAsyncSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethodRequestObjectAsyncSnippet.g.cs index 87a39c65..a1cf2a07 100644 --- a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethodRequestObjectAsyncSnippet.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethodRequestObjectAsyncSnippet.g.cs @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC +// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ namespace GoogleCSharpSnippets // [START paginated_generated_Paginated_ResourcedMethod_async] using Google.Api.Gax; using System; - using System.Linq; using System.Threading.Tasks; using Testing.Paginated; @@ -47,14 +46,14 @@ public async Task ResourcedMethodRequestObjectAsync() PagedAsyncEnumerable response = paginatedClient.ResourcedMethodAsync(request); // Iterate over all response items, lazily performing RPCs as required - await response.ForEachAsync((string item) => + await foreach (string item in response) { // Do something with each item Console.WriteLine(item); - }); + } // Or iterate over pages (of server-defined size), performing one RPC per page - await response.AsRawResponses().ForEachAsync((ResourceResponse page) => + await foreach (ResourceResponse page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); @@ -63,7 +62,7 @@ await response.AsRawResponses().ForEachAsync((ResourceResponse page) => // Do something with each item Console.WriteLine(item); } - }); + } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; diff --git a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethodRequestObjectSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethodRequestObjectSnippet.g.cs index 382855c9..6be24270 100644 --- a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethodRequestObjectSnippet.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.ResourcedMethodRequestObjectSnippet.g.cs @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC +// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod1AsyncSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod1AsyncSnippet.g.cs index c55c3715..4c29d4fe 100644 --- a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod1AsyncSnippet.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod1AsyncSnippet.g.cs @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC +// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ namespace GoogleCSharpSnippets // [START paginated_generated_Paginated_SignatureMethod_async_flattened1] using Google.Api.Gax; using System; - using System.Linq; using System.Threading.Tasks; using Testing.Paginated; @@ -44,14 +43,14 @@ public async Task SignatureMethod1Async() PagedAsyncEnumerable response = paginatedClient.SignatureMethodAsync(aString, aNumber); // Iterate over all response items, lazily performing RPCs as required - await response.ForEachAsync((Response.Types.NestedResult item) => + await foreach (Response.Types.NestedResult item in response) { // Do something with each item Console.WriteLine(item); - }); + } // Or iterate over pages (of server-defined size), performing one RPC per page - await response.AsRawResponses().ForEachAsync((Response page) => + await foreach (Response page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); @@ -60,7 +59,7 @@ await response.AsRawResponses().ForEachAsync((Response page) => // Do something with each item Console.WriteLine(item); } - }); + } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; diff --git a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod1Snippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod1Snippet.g.cs index f920ba53..8163396c 100644 --- a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod1Snippet.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod1Snippet.g.cs @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC +// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod2AsyncSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod2AsyncSnippet.g.cs index 1f4c53cd..ab83eea5 100644 --- a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod2AsyncSnippet.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod2AsyncSnippet.g.cs @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC +// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ namespace GoogleCSharpSnippets // [START paginated_generated_Paginated_SignatureMethod_async_flattened2] using Google.Api.Gax; using System; - using System.Linq; using System.Threading.Tasks; using Testing.Paginated; @@ -43,14 +42,14 @@ public async Task SignatureMethod2Async() PagedAsyncEnumerable response = paginatedClient.SignatureMethodAsync(aString: aString); // Iterate over all response items, lazily performing RPCs as required - await response.ForEachAsync((Response.Types.NestedResult item) => + await foreach (Response.Types.NestedResult item in response) { // Do something with each item Console.WriteLine(item); - }); + } // Or iterate over pages (of server-defined size), performing one RPC per page - await response.AsRawResponses().ForEachAsync((Response page) => + await foreach (Response page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); @@ -59,7 +58,7 @@ await response.AsRawResponses().ForEachAsync((Response page) => // Do something with each item Console.WriteLine(item); } - }); + } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; diff --git a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod2RequestObjectAsyncSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod2RequestObjectAsyncSnippet.g.cs index 621764ce..991d2ce7 100644 --- a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod2RequestObjectAsyncSnippet.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod2RequestObjectAsyncSnippet.g.cs @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC +// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ namespace GoogleCSharpSnippets // [START paginated_generated_Paginated_SignatureMethod2_async] using Google.Api.Gax; using System; - using System.Linq; using System.Threading.Tasks; using Testing.Paginated; @@ -47,14 +46,14 @@ public async Task SignatureMethod2RequestObjectAsync() PagedAsyncEnumerable response = paginatedClient.SignatureMethod2Async(request); // Iterate over all response items, lazily performing RPCs as required - await response.ForEachAsync((Response.Types.NestedResult item) => + await foreach (Response.Types.NestedResult item in response) { // Do something with each item Console.WriteLine(item); - }); + } // Or iterate over pages (of server-defined size), performing one RPC per page - await response.AsRawResponses().ForEachAsync((Response page) => + await foreach (Response page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); @@ -63,7 +62,7 @@ await response.AsRawResponses().ForEachAsync((Response page) => // Do something with each item Console.WriteLine(item); } - }); + } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; diff --git a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod2RequestObjectSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod2RequestObjectSnippet.g.cs index a0e883c9..d8bdb1fc 100644 --- a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod2RequestObjectSnippet.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod2RequestObjectSnippet.g.cs @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC +// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod2Snippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod2Snippet.g.cs index 0c5bbb9d..629e22c4 100644 --- a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod2Snippet.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod2Snippet.g.cs @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC +// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod3AsyncSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod3AsyncSnippet.g.cs index 87fae6bd..2a4ad016 100644 --- a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod3AsyncSnippet.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod3AsyncSnippet.g.cs @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC +// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ namespace GoogleCSharpSnippets // [START paginated_generated_Paginated_SignatureMethod_async_flattened3] using Google.Api.Gax; using System; - using System.Linq; using System.Threading.Tasks; using Testing.Paginated; @@ -41,14 +40,14 @@ public async Task SignatureMethod3Async() PagedAsyncEnumerable response = paginatedClient.SignatureMethodAsync(); // Iterate over all response items, lazily performing RPCs as required - await response.ForEachAsync((Response.Types.NestedResult item) => + await foreach (Response.Types.NestedResult item in response) { // Do something with each item Console.WriteLine(item); - }); + } // Or iterate over pages (of server-defined size), performing one RPC per page - await response.AsRawResponses().ForEachAsync((Response page) => + await foreach (Response page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); @@ -57,7 +56,7 @@ await response.AsRawResponses().ForEachAsync((Response page) => // Do something with each item Console.WriteLine(item); } - }); + } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; diff --git a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod3Snippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod3Snippet.g.cs index 300dcf5b..89d80799 100644 --- a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod3Snippet.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethod3Snippet.g.cs @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC +// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethodRequestObjectAsyncSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethodRequestObjectAsyncSnippet.g.cs index c0b54a7e..f671a3b8 100644 --- a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethodRequestObjectAsyncSnippet.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethodRequestObjectAsyncSnippet.g.cs @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC +// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ namespace GoogleCSharpSnippets // [START paginated_generated_Paginated_SignatureMethod_async] using Google.Api.Gax; using System; - using System.Linq; using System.Threading.Tasks; using Testing.Paginated; @@ -47,14 +46,14 @@ public async Task SignatureMethodRequestObjectAsync() PagedAsyncEnumerable response = paginatedClient.SignatureMethodAsync(request); // Iterate over all response items, lazily performing RPCs as required - await response.ForEachAsync((Response.Types.NestedResult item) => + await foreach (Response.Types.NestedResult item in response) { // Do something with each item Console.WriteLine(item); - }); + } // Or iterate over pages (of server-defined size), performing one RPC per page - await response.AsRawResponses().ForEachAsync((Response page) => + await foreach (Response page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); @@ -63,7 +62,7 @@ await response.AsRawResponses().ForEachAsync((Response page) => // Do something with each item Console.WriteLine(item); } - }); + } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; diff --git a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethodRequestObjectSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethodRequestObjectSnippet.g.cs index 9e2d4e75..c413c5a0 100644 --- a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethodRequestObjectSnippet.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/PaginatedClient.SignatureMethodRequestObjectSnippet.g.cs @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC +// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/snippet_metadata_testing.paginated.json b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/snippet_metadata_testing.paginated.json index 1d7c937c..3b900cdd 100644 --- a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/snippet_metadata_testing.paginated.json +++ b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.GeneratedSnippets/snippet_metadata_testing.paginated.json @@ -1,4 +1,4 @@ -{ +{ "clientLibrary": { "name": "Testing.Paginated", "language": "C_SHARP", @@ -96,12 +96,12 @@ "segments": [ { "start": 20, - "end": 81, + "end": 80, "type": "FULL" }, { - "start": 38, - "end": 79, + "start": 37, + "end": 78, "type": "SHORT" } ] @@ -215,12 +215,12 @@ "segments": [ { "start": 20, - "end": 78, + "end": 77, "type": "FULL" }, { - "start": 38, - "end": 76, + "start": 37, + "end": 75, "type": "SHORT" } ] @@ -326,12 +326,12 @@ "segments": [ { "start": 20, - "end": 77, + "end": 76, "type": "FULL" }, { - "start": 38, - "end": 75, + "start": 37, + "end": 74, "type": "SHORT" } ] @@ -429,12 +429,12 @@ "segments": [ { "start": 20, - "end": 75, + "end": 74, "type": "FULL" }, { - "start": 38, - "end": 73, + "start": 37, + "end": 72, "type": "SHORT" } ] @@ -526,12 +526,12 @@ "segments": [ { "start": 20, - "end": 81, + "end": 80, "type": "FULL" }, { - "start": 38, - "end": 79, + "start": 37, + "end": 78, "type": "SHORT" } ] @@ -623,12 +623,12 @@ "segments": [ { "start": 20, - "end": 81, + "end": 80, "type": "FULL" }, { - "start": 38, - "end": 79, + "start": 37, + "end": 78, "type": "SHORT" } ] @@ -734,12 +734,12 @@ "segments": [ { "start": 20, - "end": 77, + "end": 76, "type": "FULL" }, { - "start": 38, - "end": 75, + "start": 37, + "end": 74, "type": "SHORT" } ] @@ -845,12 +845,12 @@ "segments": [ { "start": 20, - "end": 77, + "end": 76, "type": "FULL" }, { - "start": 38, - "end": 75, + "start": 37, + "end": 74, "type": "SHORT" } ] @@ -964,12 +964,12 @@ "segments": [ { "start": 20, - "end": 78, + "end": 77, "type": "FULL" }, { - "start": 38, - "end": 76, + "start": 37, + "end": 75, "type": "SHORT" } ] @@ -1083,12 +1083,12 @@ "segments": [ { "start": 20, - "end": 78, + "end": 77, "type": "FULL" }, { - "start": 38, - "end": 76, + "start": 37, + "end": 75, "type": "SHORT" } ] diff --git a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.Snippets/PaginatedClientSnippets.g.cs b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.Snippets/PaginatedClientSnippets.g.cs index d205523d..04a5cb0e 100644 --- a/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.Snippets/PaginatedClientSnippets.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/Paginated/Testing.Paginated.Snippets/PaginatedClientSnippets.g.cs @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC +// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ namespace GoogleCSharpSnippets { using Google.Api.Gax; using System; - using System.Linq; using System.Threading.Tasks; using Testing.Paginated; @@ -90,14 +89,14 @@ public async Task SignatureMethodRequestObjectAsync() PagedAsyncEnumerable response = paginatedClient.SignatureMethodAsync(request); // Iterate over all response items, lazily performing RPCs as required - await response.ForEachAsync((Response.Types.NestedResult item) => + await foreach (Response.Types.NestedResult item in response) { // Do something with each item Console.WriteLine(item); - }); + } // Or iterate over pages (of server-defined size), performing one RPC per page - await response.AsRawResponses().ForEachAsync((Response page) => + await foreach (Response page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); @@ -106,7 +105,7 @@ await response.AsRawResponses().ForEachAsync((Response page) => // Do something with each item Console.WriteLine(item); } - }); + } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; @@ -182,14 +181,14 @@ public async Task SignatureMethod1Async() PagedAsyncEnumerable response = paginatedClient.SignatureMethodAsync(aString, aNumber); // Iterate over all response items, lazily performing RPCs as required - await response.ForEachAsync((Response.Types.NestedResult item) => + await foreach (Response.Types.NestedResult item in response) { // Do something with each item Console.WriteLine(item); - }); + } // Or iterate over pages (of server-defined size), performing one RPC per page - await response.AsRawResponses().ForEachAsync((Response page) => + await foreach (Response page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); @@ -198,7 +197,7 @@ await response.AsRawResponses().ForEachAsync((Response page) => // Do something with each item Console.WriteLine(item); } - }); + } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; @@ -272,14 +271,14 @@ public async Task SignatureMethod2Async() PagedAsyncEnumerable response = paginatedClient.SignatureMethodAsync(aString: aString); // Iterate over all response items, lazily performing RPCs as required - await response.ForEachAsync((Response.Types.NestedResult item) => + await foreach (Response.Types.NestedResult item in response) { // Do something with each item Console.WriteLine(item); - }); + } // Or iterate over pages (of server-defined size), performing one RPC per page - await response.AsRawResponses().ForEachAsync((Response page) => + await foreach (Response page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); @@ -288,7 +287,7 @@ await response.AsRawResponses().ForEachAsync((Response page) => // Do something with each item Console.WriteLine(item); } - }); + } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; @@ -358,14 +357,14 @@ public async Task SignatureMethod3Async() PagedAsyncEnumerable response = paginatedClient.SignatureMethodAsync(); // Iterate over all response items, lazily performing RPCs as required - await response.ForEachAsync((Response.Types.NestedResult item) => + await foreach (Response.Types.NestedResult item in response) { // Do something with each item Console.WriteLine(item); - }); + } // Or iterate over pages (of server-defined size), performing one RPC per page - await response.AsRawResponses().ForEachAsync((Response page) => + await foreach (Response page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); @@ -374,7 +373,7 @@ await response.AsRawResponses().ForEachAsync((Response page) => // Do something with each item Console.WriteLine(item); } - }); + } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; @@ -456,14 +455,14 @@ public async Task SignatureMethod2RequestObjectAsync() PagedAsyncEnumerable response = paginatedClient.SignatureMethod2Async(request); // Iterate over all response items, lazily performing RPCs as required - await response.ForEachAsync((Response.Types.NestedResult item) => + await foreach (Response.Types.NestedResult item in response) { // Do something with each item Console.WriteLine(item); - }); + } // Or iterate over pages (of server-defined size), performing one RPC per page - await response.AsRawResponses().ForEachAsync((Response page) => + await foreach (Response page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); @@ -472,7 +471,7 @@ await response.AsRawResponses().ForEachAsync((Response page) => // Do something with each item Console.WriteLine(item); } - }); + } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; @@ -554,14 +553,14 @@ public async Task ResourcedMethodRequestObjectAsync() PagedAsyncEnumerable response = paginatedClient.ResourcedMethodAsync(request); // Iterate over all response items, lazily performing RPCs as required - await response.ForEachAsync((string item) => + await foreach (string item in response) { // Do something with each item Console.WriteLine(item); - }); + } // Or iterate over pages (of server-defined size), performing one RPC per page - await response.AsRawResponses().ForEachAsync((ResourceResponse page) => + await foreach (ResourceResponse page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); @@ -570,7 +569,7 @@ await response.AsRawResponses().ForEachAsync((ResourceResponse page) => // Do something with each item Console.WriteLine(item); } - }); + } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; @@ -644,14 +643,14 @@ public async Task ResourcedMethod1Async() PagedAsyncEnumerable response = paginatedClient.ResourcedMethodAsync(name); // Iterate over all response items, lazily performing RPCs as required - await response.ForEachAsync((string item) => + await foreach (string item in response) { // Do something with each item Console.WriteLine(item); - }); + } // Or iterate over pages (of server-defined size), performing one RPC per page - await response.AsRawResponses().ForEachAsync((ResourceResponse page) => + await foreach (ResourceResponse page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); @@ -660,7 +659,7 @@ await response.AsRawResponses().ForEachAsync((ResourceResponse page) => // Do something with each item Console.WriteLine(item); } - }); + } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; @@ -734,14 +733,14 @@ public async Task ResourcedMethod1ResourceNamesAsync() PagedAsyncEnumerable response = paginatedClient.ResourcedMethodAsync(name); // Iterate over all response items, lazily performing RPCs as required - await response.ForEachAsync((string item) => + await foreach (string item in response) { // Do something with each item Console.WriteLine(item); - }); + } // Or iterate over pages (of server-defined size), performing one RPC per page - await response.AsRawResponses().ForEachAsync((ResourceResponse page) => + await foreach (ResourceResponse page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); @@ -750,7 +749,7 @@ await response.AsRawResponses().ForEachAsync((ResourceResponse page) => // Do something with each item Console.WriteLine(item); } - }); + } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; @@ -826,14 +825,14 @@ public async Task ResourcedMethod2Async() PagedAsyncEnumerable response = paginatedClient.ResourcedMethodAsync(name, extraString: extraString); // Iterate over all response items, lazily performing RPCs as required - await response.ForEachAsync((string item) => + await foreach (string item in response) { // Do something with each item Console.WriteLine(item); - }); + } // Or iterate over pages (of server-defined size), performing one RPC per page - await response.AsRawResponses().ForEachAsync((ResourceResponse page) => + await foreach (ResourceResponse page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); @@ -842,7 +841,7 @@ await response.AsRawResponses().ForEachAsync((ResourceResponse page) => // Do something with each item Console.WriteLine(item); } - }); + } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; @@ -918,14 +917,14 @@ public async Task ResourcedMethod2ResourceNamesAsync() PagedAsyncEnumerable response = paginatedClient.ResourcedMethodAsync(name, extraString: extraString); // Iterate over all response items, lazily performing RPCs as required - await response.ForEachAsync((string item) => + await foreach (string item in response) { // Do something with each item Console.WriteLine(item); - }); + } // Or iterate over pages (of server-defined size), performing one RPC per page - await response.AsRawResponses().ForEachAsync((ResourceResponse page) => + await foreach (ResourceResponse page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); @@ -934,7 +933,7 @@ await response.AsRawResponses().ForEachAsync((ResourceResponse page) => // Do something with each item Console.WriteLine(item); } - }); + } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; diff --git a/Google.Api.Generator.Tests/ProtoTests/PublishingSettings/Testing.PublishingSettings.GeneratedSnippets/ServiceWithMethodSettingsClient.PaginatedAutoPopulatedRequestObjectAsyncSnippet.g.cs b/Google.Api.Generator.Tests/ProtoTests/PublishingSettings/Testing.PublishingSettings.GeneratedSnippets/ServiceWithMethodSettingsClient.PaginatedAutoPopulatedRequestObjectAsyncSnippet.g.cs index d5d2066d..d2cf227f 100644 --- a/Google.Api.Generator.Tests/ProtoTests/PublishingSettings/Testing.PublishingSettings.GeneratedSnippets/ServiceWithMethodSettingsClient.PaginatedAutoPopulatedRequestObjectAsyncSnippet.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/PublishingSettings/Testing.PublishingSettings.GeneratedSnippets/ServiceWithMethodSettingsClient.PaginatedAutoPopulatedRequestObjectAsyncSnippet.g.cs @@ -19,7 +19,6 @@ namespace GoogleCSharpSnippets // [START unknown_generated_ServiceWithMethodSettings_PaginatedAutoPopulated_async] using Google.Api.Gax; using System; - using System.Linq; using System.Threading.Tasks; using Testing.PublishingSettings; @@ -43,14 +42,14 @@ public async Task PaginatedAutoPopulatedRequestObjectAsync() PagedAsyncEnumerable response = serviceWithMethodSettingsClient.PaginatedAutoPopulatedAsync(request); // Iterate over all response items, lazily performing RPCs as required - await response.ForEachAsync((Response item) => + await foreach (Response item in response) { // Do something with each item Console.WriteLine(item); - }); + } // Or iterate over pages (of server-defined size), performing one RPC per page - await response.AsRawResponses().ForEachAsync((PaginatedResponse page) => + await foreach (PaginatedResponse page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); @@ -59,7 +58,7 @@ await response.AsRawResponses().ForEachAsync((PaginatedResponse page) => // Do something with each item Console.WriteLine(item); } - }); + } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; diff --git a/Google.Api.Generator.Tests/ProtoTests/PublishingSettings/Testing.PublishingSettings.GeneratedSnippets/snippet_metadata_testing.publishingsettings.json b/Google.Api.Generator.Tests/ProtoTests/PublishingSettings/Testing.PublishingSettings.GeneratedSnippets/snippet_metadata_testing.publishingsettings.json index f6d813ee..a0c37050 100644 --- a/Google.Api.Generator.Tests/ProtoTests/PublishingSettings/Testing.PublishingSettings.GeneratedSnippets/snippet_metadata_testing.publishingsettings.json +++ b/Google.Api.Generator.Tests/ProtoTests/PublishingSettings/Testing.PublishingSettings.GeneratedSnippets/snippet_metadata_testing.publishingsettings.json @@ -875,12 +875,12 @@ "segments": [ { "start": 20, - "end": 77, + "end": 76, "type": "FULL" }, { - "start": 38, - "end": 75, + "start": 37, + "end": 74, "type": "SHORT" } ] diff --git a/Google.Api.Generator.Tests/ProtoTests/PublishingSettings/Testing.PublishingSettings.Snippets/ServiceWithMethodSettingsClientSnippets.g.cs b/Google.Api.Generator.Tests/ProtoTests/PublishingSettings/Testing.PublishingSettings.Snippets/ServiceWithMethodSettingsClientSnippets.g.cs index a5a157df..c242b15b 100644 --- a/Google.Api.Generator.Tests/ProtoTests/PublishingSettings/Testing.PublishingSettings.Snippets/ServiceWithMethodSettingsClientSnippets.g.cs +++ b/Google.Api.Generator.Tests/ProtoTests/PublishingSettings/Testing.PublishingSettings.Snippets/ServiceWithMethodSettingsClientSnippets.g.cs @@ -20,7 +20,6 @@ namespace GoogleCSharpSnippets using Google.Api.Gax.Grpc; using Google.LongRunning; using System; - using System.Linq; using System.Threading.Tasks; using Testing.PublishingSettings; @@ -261,14 +260,14 @@ public async Task PaginatedAutoPopulatedRequestObjectAsync() PagedAsyncEnumerable response = serviceWithMethodSettingsClient.PaginatedAutoPopulatedAsync(request); // Iterate over all response items, lazily performing RPCs as required - await response.ForEachAsync((Response item) => + await foreach (Response item in response) { // Do something with each item Console.WriteLine(item); - }); + } // Or iterate over pages (of server-defined size), performing one RPC per page - await response.AsRawResponses().ForEachAsync((PaginatedResponse page) => + await foreach (PaginatedResponse page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); @@ -277,7 +276,7 @@ await response.AsRawResponses().ForEachAsync((PaginatedResponse page) => // Do something with each item Console.WriteLine(item); } - }); + } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; From e2bbea491699acac0ba5ab47c5d3c5ec6e758367 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Mon, 17 Nov 2025 14:04:47 +0000 Subject: [PATCH 3/3] fix: reinstate System.Linq.AsyncEnumerable for integration tests --- Directory.Packages.props | 1 + .../Google.Api.Generator.IntegrationTests.csproj | 1 + 2 files changed, 2 insertions(+) diff --git a/Directory.Packages.props b/Directory.Packages.props index d55981ab..19525eb8 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -24,6 +24,7 @@ + diff --git a/Google.Api.Generator.IntegrationTests/Google.Api.Generator.IntegrationTests.csproj b/Google.Api.Generator.IntegrationTests/Google.Api.Generator.IntegrationTests.csproj index 0ef7d579..670cd079 100644 --- a/Google.Api.Generator.IntegrationTests/Google.Api.Generator.IntegrationTests.csproj +++ b/Google.Api.Generator.IntegrationTests/Google.Api.Generator.IntegrationTests.csproj @@ -12,6 +12,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive +