Here are two examples:
This works great:
void Main() { var list = Queryable.ProjectTo(typeof(Projection)); } public static class QueryableExtensions { public static ProjectionList<T> ProjectTo<T>(this IQueryable<T> queryable, Type projectionType) { return new ProjectionList<T>(queryable, projectionType); } }
This causes the following error:
Using the generic method 'QueryableExtensions.ProjectTo (System.Linq.IQueryable)' requires 2 arguments of type
void Main() { var list = Queryable.ProjectTo<Projection>(); } public static class QueryableExtensions { public static ProjectionList<T, P> ProjectTo<T, P>(this IQueryable<T> queryable) { return new ProjectionList<T, P>(queryable); } }
Of course, the first example requires 1 type argument, however, the compiler can understand what it is, so I do not need to provide it. In the second example, 2 type arguments are required, but the compiler knows what T is, so it requires not only one that cannot be output?
For the record, I use the first example, just fine in my code, but I like the syntax of the second much better, and there may be times when I would like to have a common type of projection. Is there any way to achieve this, or am I barking the wrong tree?
Thanks!
source share