csharp 扩展方法和元组

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 扩展方法和元组相关的知识,希望对你有一定的参考价值。

// 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);
}

以上是关于csharp 扩展方法和元组的主要内容,如果未能解决你的问题,请参考以下文章

序列类型

python元组(tuple)使用示例+常用方法+列表(list)和元组(tuple)的异同?

python基本数据类型之列表和元组

#9 Python列表和元组

Python列表和元组的使用方法及区别 详解

Python列表和元组的使用方法及区别 详解