| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- 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<T> OrderByPropertyName<T>
- (
- this IEnumerable<T> 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<T> OrderByDirection<T, TKey>
- (
- this IEnumerable<T> items,
- Func<T, TKey> 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);
- }
- }
- }
- }
|