扩展方法。不包含接受第一个类型参数的扩展方法的定义

时间:2014-04-10 13:04:48

标签: c# linq extension-methods

我已经写了以下扩展方法:

using System;
using System.Collections.Generic;
using System.Linq;

namespace Cortana.Extensions
{
    public static class LinqExtensions
    {
        /// <summary>
        /// Linq method to paginate data.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source">The source.</param>
        /// <param name="pageSize">Size of the page.</param>
        /// <returns></returns>
        public static List<IEnumerable<T>> ToPages<T>(this IEnumerable<T> source, int pageSize)
        {
            List<IEnumerable<T>> pagedSource = source
               .Select((x, index) => new { x, index })
               .GroupBy(a => a.index / pageSize)
               .Select(x => x.Select(i => i.x))
               .ToList();

            return pagedSource;
        }
    }
}

像这样被召唤:

using Cortana.Extensions;
...
var pagedAssessments = Model.SymptomAssessmentHistory
    .Where(x => x.IsComplete())
    .Where(x => (x.SymptomAssessmentUID != Model.CurrentSymptomAssessment.SymptomAssessmentUID))
    .OrderByDescending(x => x.TimeTaken)
    .Take(numColumnsToShow)
    .ToPages(numColumnsToShow);

但是我得到以下编译器错误:

'System.Collections.Generic.IEnumerable<Cortana.Models.WebApi.SymptomAssessment>' does not contain a definition for 'ToPages' and no extension method 'ToPages' accepting a first argument of type 'System.Collections.Generic.IEnumerable<Cortana.Models.WebApi.SymptomAssessment>' could be found (are you missing a using directive or an assembly reference?)

一切似乎都到位了,我错过了什么?

1 个答案:

答案 0 :(得分:0)

原来我们的版本中有人破坏了某些东西。感谢大家的帮助。

如果这有助于其他任何人 - 删除您的代码,并确保您可以在没有它的情况下构建...