Ejemplo n.º 1
0
        internal static INodeComparer <TResult, TStep> CreateComparer <TResult, TKey, TStep>(Func <TResult, TKey> keySelector, IComparer <TKey> keyComparer, bool descending)
        {
            if (keyComparer != null)
            {
                return(new NormalComparer <TStep, TResult, TKey>(keySelector, keyComparer, descending));
            }

            var comparer = default(INodeComparer <TResult, TStep>);

            switch (Type.GetTypeCode(typeof(TKey)))
            {
            case TypeCode.Byte:
            case TypeCode.Decimal:
            case TypeCode.Double:
            case TypeCode.Int16:
            case TypeCode.Int32:
            case TypeCode.Int64:
            case TypeCode.SByte:
            case TypeCode.Single:
            case TypeCode.UInt16:
            case TypeCode.UInt32:
            case TypeCode.UInt64:
                comparer = new HeuristicComparer <TStep, TResult, TKey>(keySelector, descending);
                break;

            default:
                comparer = new NormalComparer <TStep, TResult, TKey>(keySelector, null, descending);
                break;
            }
            return(comparer);
        }
Ejemplo n.º 2
0
        internal HeuristicSearchOrderBy <TFactor, TStep> CreateOrderedEnumerable <TKey>(Func <TFactor, TKey> keySelector, IComparer <TKey> comparer, bool descending)
        {
            if (keySelector == null)
            {
                throw new ArgumentNullException(nameof(keySelector));
            }

            var comparer1 = _nodeComparer;
            var comparer2 = new NormalComparer <TFactor, TKey, TStep>(keySelector, null, descending);

            _nodeComparer = new CombinedComparer <TFactor, TStep>(comparer1, comparer2);

            return(this);
        }