using System; using System.Linq; using System.Linq.Expressions; namespace Gestor.Application.Helpers; public static class QueryableHelper { public static IOrderedQueryable OrderBy(this IQueryable source, string propertyName) { return source.OrderBy(ToLambda(propertyName)); } public static IOrderedQueryable OrderByDescending(this IQueryable source, string propertyName) { return source.OrderByDescending(ToLambda(propertyName)); } private static Expression> ToLambda(string propertyName) { ParameterExpression parameterExpression = Expression.Parameter(typeof(T)); return Expression.Lambda>(Expression.Convert(Expression.Property(parameterExpression, propertyName), typeof(object)), new ParameterExpression[1] { parameterExpression }); } }