using System.Collections; using System.Collections.Generic; using System; using System.Reflection; using System.Text.RegularExpressions; namespace Rokojori { public class MultiValueSorter { List> valueSorters = new List>(); public void AddValueSorter( Func getFloatValue, bool reverse = false ) { var valueSorter = ValueSorter.Create( getFloatValue, reverse ); valueSorters.Add( valueSorter ); } public void Sort( List data ) { valueSorters.ForEach( v => v.ClearCache() ); data.Sort( ( a, b ) => Compare( a, b ) ); } public void Sort( int index, int count, List data ) { valueSorters.ForEach( v => v.ClearCache() ); data.Sort( index, count, Comparer.Create( ( a, b ) => Compare( a, b ) ) ); } public int Compare( T a, T b ) { for ( int i = 0; i < valueSorters.Count; i++ ) { var valueProvider = valueSorters[ 0 ]; var result = valueProvider.Compare( a, b ); if ( result != 0 ) { return result; } } return 0; } public static MultiValueSorter Create( params Func[] valueSorterFunctions ) { var multiSorter = new MultiValueSorter(); for ( int i = 0; i < valueSorterFunctions.Length; i++ ) { multiSorter.AddValueSorter( valueSorterFunctions[ i ] ); } return multiSorter; } public static void SortBy( List data, params Func[] valueSorterFunctions ) { Create( valueSorterFunctions ).Sort( data ); } } }