private static async Task <IEnumerable <TResource> > ReadFromBundleWithContinuationAsync <TResource>( this Bundle bundle, IFhirService fhirService, int?count = null) where TResource : Resource { EnsureArg.IsNotNull(fhirService, nameof(fhirService)); var resources = new List <TResource>(); Action <Bundle> storeResources = (bundle) => { foreach (var r in bundle.ReadFromBundle <TResource>(count)) { if (count == 0) { break; } resources.Add(r); if (count != null) { count--; } } }; storeResources.Invoke(bundle); await foreach (var currentBundle in fhirService.IterateOverAdditionalBundlesAsync(bundle)) { storeResources.Invoke(currentBundle); } return(resources); }