...
, , .
return items.Select(x=>x as SomeInterface).ToList();
If you do this often, the extension method may still be useful. It should not be Tolist / Cast / ToList, as you already mentioned. Cast will accept IEnumerable already, but you can create an overload that accepts IQueryable, something like this (untested).
public IEnumerable<TResult> Cast<T, TResult>(this IQueryable<T> input)
{
return input.AsEnumerable().Cast<TResult>();
}
This will shorten your code to this:
return items.Cast<SomeClass, SomeInterface>.ToList();
source
share