我有我想写的这个方法:
public static IQueryable<TSource> CutTo<TSource>(this IQueryable<TSource> source, Func<int> func)
{
int index = func();
// here I can write something for all types or switch all
// the types and write code for every type
}
为所有 TSource 类型编写此代码的最简单方法是什么?
编辑:黑熊写道,这已经适用于所有类型,但事实并非如此。Mono 是这样写的:
public static IQueryable<TSource> Where<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
{
Check.SourceAndPredicate (source, predicate);
return source.Provider.CreateQuery<TSource> (
StaticCall (
MakeGeneric (MethodBase.GetCurrentMethod (), typeof (TSource)),
source.Expression,
Expression.Quote (predicate)));
}