我有两种方法,如下所示。我想在一种方法中收集这两种方法。
当我确实喜欢以下两种方法时,效果很好
public static async Task<GridResult<List<T>>> GetGridResult<T, TSearchFilter>(
this IQueryable<T> query,
QueryFilter<TSearchFilter> queryFilter) where TSearchFilter : class
{
}
public static async Task<GridResult<List<T>>> GetGridResult<T>(
this IQueryable<T> query,
QueryFilter queryFilter)
{
}
因此,我通过将默认null值设置为QueryFilter<TSearchFilter> queryFilter.
但是,当我做了一种方法时,给了我错误
public static async Task<GridResult<List<T>>> GetGridResult<T, TSearchFilter>(
this IQueryable<T> query,
QueryFilter<TSearchFilter> queryFilter = null) where TSearchFilter : class
{
}
但是我不能通过一个参数来调用我的方法,比如query.GetGridResult(queryFilter). 它给了我错误
'IQueryableExtensions.GetGridResult(IQueryable, QueryFilter)' 不能从用法中推断出来。尝试明确指定类型参数。
我该如何解决这个错误?
public class QueryFilter<TSearchFilter> where TSearchFilter: class
{
public QueryFilter()
{
SearchFilter = (TSearchFilter)Activator.CreateInstance(typeof(TSearchFilter));
}
public string SortBy { get; set; }
public bool IsSortAscending { get; set; }
public int PageFirstIndex { get; set; }
public byte PageSize { get; set; }
public TSearchFilter SearchFilter { get; set; }
}
public class QueryFilter
{
public string SortBy { get; set; }
public bool IsSortAscending { get; set; }
public int PageFirstIndex { get; set; }
public byte PageSize { get; set; }
}
ABOUTYOU
杨魅力
ibeautiful
相关分类