//private static int SortUnit<T>(T[] array, int low, int high, IComparer<T> comparer,bool asc) //{ // T key = array[low]; // while (low < high) // { // bool result = asc ? comparer.Compare(array[high], key) > -1 : comparer.Compare(array[high], key) < 1; // while (result && high > low) // { // --high; // result = asc ? comparer.Compare(array[high], key) > -1 : comparer.Compare(array[high], key) < 1; // } // array[low] = array[high]; // result = asc ? comparer.Compare(array[low], key) <1 : comparer.Compare(array[low], key) >-1; // while (result && high > low) // { // ++low; // result = asc ? comparer.Compare(array[low], key) < 1 : comparer.Compare(array[low], key) > -1; // } // array[high] = array[low]; // } // array[low] = key; // return high; //} //private static void SortCore<T>(T[] array,int low,int high, IComparer<T> comparer, bool asc) //{ // if (low >= high) // return; // int index = SortUnit(array, low, high,comparer,asc); // SortCore(array, low, index - 1,comparer,asc); // SortCore(array, index + 1, high,comparer,asc); //} public static IEnumerable <T> Sort <T>(this IEnumerable <T> source, bool asc = true, IComparer <T> comparer = null) { if (comparer == null) { comparer = new CommonComparer <T>(); } T[] array = source.ToArray(); Array.Sort(array, comparer); if (!asc) { return(array.Reverse()); } return(array); }
public DataPrivilegeContext(List <TRule> rules, TDbContext dbContext, IDataPrivilegeFieldProvider dataPrivilegeFieldProvider, DataPrivilegeVisitor <TDbContext, TEntity> dataPrivilegeVisitor) { Rules = rules; var comparer = new CommonComparer <TRule>((x, y) => { int left = x.ConditionExpression.GetHashCode(); int right = y.ConditionExpression.GetHashCode(); return(left.CompareTo(right)); }); Rules.Sort(comparer); DbContext = dbContext; DataPrivilegeFieldProvider = dataPrivilegeFieldProvider; DataPrivilegeVisitor = dataPrivilegeVisitor; }