public void SetCaseType(ECaseType type) { _caseType = type; }
public static string ConvertCase(this string str, ECaseType caseType) => caseType switch {
public static string[] GetProperties(this string str, char splitSeparator = '.', ECaseType caseType = ECaseType.PascalCase) { var properties = str.Split(splitSeparator, StringSplitOptions.RemoveEmptyEntries); return(properties.Select(x => x.ConvertCase(caseType)).ToArray()); }
/// <summary> /// Filter by asc or desc passing an string /// </summary> /// <param name="source">The source IQueryable</param> /// <param name="sort">Asc,prop / desc,prop</param> /// <typeparam name="TSource">Type of data</typeparam> public static IOrderedQueryable <TSource> OrderBy <TSource>(this IQueryable <TSource> source, string sort, ECaseType caseType = ECaseType.PascalCase) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (string.IsNullOrEmpty(sort) || string.IsNullOrWhiteSpace(sort)) { return((IOrderedQueryable <TSource>)source); } var sorter = sort.Split(','); var properties = sorter[0].GetProperties('.', caseType); return(sorter[1].Equals("asc", StringComparison.InvariantCultureIgnoreCase) ? source.ExecuteOrderBy("OrderBy", properties) : source.ExecuteOrderBy("OrderByDescending", properties)); }