I have a grid control that have a DataSource property as Object, Now I want to cast my DataSource to IQueryable<T> to take and skip Like this code
var pagedData = ((IQueryable<T>) DataSource).Skip(20).Take(10);
But I don’t know how can I cast Object to IQueryable<T>? also most of the time type of data is IQueryable<AnonymousType>.
There will almost certainly be better ways to deal with this, but to answer your question as asked, you can use
dynamic:And call it as:
If you are on .NET 3.5, you’ll have to use reflection, unfortunately.