IQueryable<T> Extension Method not working
- by Micah
How can i make an extension method that will work like this
public static class Extensions<T>
{
public static IQueryable<T> Sort(this IQueryable<T> query, string sortField, SortDirection direction)
{
// System.Type dataSourceType = query.GetType();
//System.Type dataItemType = typeof(object);
//if (dataSourceType.HasElementType)
//{
// dataItemType = dataSourceType.GetElementType();
//}
//else if (dataSourceType.IsGenericType)
//{
// dataItemType = dataSourceType.GetGenericArguments()[0];
//}
//var fieldType = dataItemType.GetProperty(sortField);
if (direction == SortDirection.Ascending)
return query.OrderBy(s => s.GetType().GetProperty(sortField));
return query.OrderByDescending(s => s.GetType().GetProperty(sortField));
}
}
Currently that says "Extension methods must be defined in a non-generic static class".
How do i do this?