public virtual Pageable <PolicyAssignmentResource> GetAll(string filter = null, int?top = null, CancellationToken cancellationToken = default) { if (Id.ResourceType == ResourceGroupResource.ResourceType) { Page <PolicyAssignmentResource> FirstPageFunc(int?pageSizeHint) { using var scope = _policyAssignmentClientDiagnostics.CreateScope("PolicyAssignmentCollection.GetAll"); scope.Start(); try { var response = _policyAssignmentRestClient.ListForResourceGroup(Id.SubscriptionId, Id.ResourceGroupName, filter, top, cancellationToken: cancellationToken); return(Page.FromValues(response.Value.Value.Select(value => new PolicyAssignmentResource(Client, value)), response.Value.NextLink, response.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } } Page <PolicyAssignmentResource> NextPageFunc(string nextLink, int?pageSizeHint) { using var scope = _policyAssignmentClientDiagnostics.CreateScope("PolicyAssignmentCollection.GetAll"); scope.Start(); try { var response = _policyAssignmentRestClient.ListForResourceGroupNextPage(nextLink, Id.SubscriptionId, Id.ResourceGroupName, filter, top, cancellationToken: cancellationToken); return(Page.FromValues(response.Value.Value.Select(value => new PolicyAssignmentResource(Client, value)), response.Value.NextLink, response.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } } return(PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc)); } else if (Id.ResourceType == ManagementGroupResource.ResourceType) { Page <PolicyAssignmentResource> FirstPageFunc(int?pageSizeHint) { using var scope = _policyAssignmentClientDiagnostics.CreateScope("PolicyAssignmentCollection.GetAll"); scope.Start(); try { var response = _policyAssignmentRestClient.ListForManagementGroup(Id.Name, filter, top, cancellationToken: cancellationToken); return(Page.FromValues(response.Value.Value.Select(value => new PolicyAssignmentResource(Client, value)), response.Value.NextLink, response.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } } Page <PolicyAssignmentResource> NextPageFunc(string nextLink, int?pageSizeHint) { using var scope = _policyAssignmentClientDiagnostics.CreateScope("PolicyAssignmentCollection.GetAll"); scope.Start(); try { var response = _policyAssignmentRestClient.ListForManagementGroupNextPage(nextLink, Id.Name, filter, top, cancellationToken: cancellationToken); return(Page.FromValues(response.Value.Value.Select(value => new PolicyAssignmentResource(Client, value)), response.Value.NextLink, response.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } } return(PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc)); } else if (Id.ResourceType == SubscriptionResource.ResourceType) { Page <PolicyAssignmentResource> FirstPageFunc(int?pageSizeHint) { using var scope = _policyAssignmentClientDiagnostics.CreateScope("PolicyAssignmentCollection.GetAll"); scope.Start(); try { var response = _policyAssignmentRestClient.List(Id.SubscriptionId, filter, top, cancellationToken: cancellationToken); return(Page.FromValues(response.Value.Value.Select(value => new PolicyAssignmentResource(Client, value)), response.Value.NextLink, response.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } } Page <PolicyAssignmentResource> NextPageFunc(string nextLink, int?pageSizeHint) { using var scope = _policyAssignmentClientDiagnostics.CreateScope("PolicyAssignmentCollection.GetAll"); scope.Start(); try { var response = _policyAssignmentRestClient.ListNextPage(nextLink, Id.SubscriptionId, filter, top, cancellationToken: cancellationToken); return(Page.FromValues(response.Value.Value.Select(value => new PolicyAssignmentResource(Client, value)), response.Value.NextLink, response.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } } return(PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc)); } else { Page <PolicyAssignmentResource> FirstPageFunc(int?pageSizeHint) { using var scope = _policyAssignmentClientDiagnostics.CreateScope("PolicyAssignmentCollection.GetAll"); scope.Start(); try { var response = _policyAssignmentRestClient.ListForResource(Id.SubscriptionId, Id.ResourceGroupName, Id.ResourceType.Namespace, Id.Parent.SubstringAfterProviderNamespace(), Id.ResourceType.GetLastType(), Id.Name, filter, top, cancellationToken: cancellationToken); return(Page.FromValues(response.Value.Value.Select(value => new PolicyAssignmentResource(Client, value)), response.Value.NextLink, response.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } } Page <PolicyAssignmentResource> NextPageFunc(string nextLink, int?pageSizeHint) { using var scope = _policyAssignmentClientDiagnostics.CreateScope("PolicyAssignmentCollection.GetAll"); scope.Start(); try { var response = _policyAssignmentRestClient.ListForResourceNextPage(nextLink, Id.SubscriptionId, Id.ResourceGroupName, Id.ResourceType.Namespace, Id.Parent.SubstringAfterProviderNamespace(), Id.ResourceType.GetLastType(), Id.Name, filter, top, cancellationToken: cancellationToken); return(Page.FromValues(response.Value.Value.Select(value => new PolicyAssignmentResource(Client, value)), response.Value.NextLink, response.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } } return(PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc)); } }