using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace comal.timesheets.Data_Classes { public static class SearchUtils { public static String UpperCaseFirst(string s) { char[] a = s.ToCharArray(); a[0] = char.ToUpper(a[0]); return new string(a); } public static String LowerCaseFirst(string s) { char[] a = s.ToCharArray(); a[0] = char.ToLower(a[0]); return new string(a); } public static String UpperCaseSecond(string s) { char[] a = s.ToCharArray(); if (a.Length >= 2) { a[0] = char.ToUpper(a[0]); a[1] = char.ToUpper(a[1]); return new string(a); } else return s; } public static String UpperCaseThird(string s) { char[] a = s.ToCharArray(); if (a.Length >= 3) { a[0] = char.ToUpper(a[0]); a[1] = char.ToUpper(a[1]); a[2] = char.ToUpper(a[2]); return new string(a); } else return s; } public static String UpperCaseFourth(string s) { char[] a = s.ToCharArray(); if (a.Length >= 4) { a[0] = char.ToUpper(a[0]); a[1] = char.ToUpper(a[1]); a[2] = char.ToUpper(a[2]); a[3] = char.ToUpper(a[3]); return new string(a); } else return s; } public enum SortDirection { Default, Ascending, Descending } public static IOrderedEnumerable OrderByPropertyName ( this IEnumerable items, string propertyName, SortDirection sortDirection = SortDirection.Ascending ) { var propInfo = typeof(T).GetProperty(propertyName); return items.OrderByDirection(x => propInfo.GetValue(x, null), sortDirection); } public static IOrderedEnumerable OrderByDirection ( this IEnumerable items, Func keyExpression, SortDirection sortDirection = SortDirection.Ascending ) { switch (sortDirection) { case SortDirection.Ascending: return items.OrderBy(keyExpression); case SortDirection.Descending: return items.OrderByDescending(keyExpression); default: return items.OrderBy(keyExpression); } } } }