// Extension method definition
public static PagedCollection<TResult> ToPagedCollection<T, TResult>(
this (IEnumerable<T> entitiesToMap, int totalCount) entitiesAndCount, // This is the important bit
FilterParameters filterParameters,
Func<T, TResult> map)
{
return entitiesAndCount.entitiesToMap.ToPagedCollection(entitiesAndCount.totalCount, filterParameters?.PagingParameters?.PageSize, map);
}
// Consumption of the extension method
public async Task<PagedCollection<User>> FilterUsersAsync(FilterParameters filter)
{
var bucket = filter.BuildSearchPredicateBucket(AspNetUserFields.Email);
var prefetch = CreateUserRolesPrefetchPath();
// Repository returns a tuple
var entitiesAndCount = await _userRepository.FetchAndCountEntitiesAsync(filter, bucket, prefetch);
// Tuple used as the main extension method argument
return entitiesAndCount.ToPagedCollection(filter, UserMappingExtensions.ToModel);
}