Example #1
0
        public virtual SortField CreateSortField(bool reverse)
        {
            if (Converter == null)
            {
                return(new SortField(FieldName, SortField.STRING, reverse));
            }

            var propertyType = propertyInfo.PropertyType;

            FieldComparatorSource source;

            if (typeof(IComparable).IsAssignableFrom(propertyType))
            {
                source = new NonGenericConvertableFieldComparatorSource(propertyType, Converter);
            }
            else if (typeof(IComparable <>).MakeGenericType(propertyType).IsAssignableFrom(propertyType))
            {
                source = new GenericConvertableFieldComparatorSource(propertyType, Converter);
            }
            else
            {
                throw new NotSupportedException("Unsupported sort field type (does not implement IComparable): " +
                                                propertyType);
            }

            return(new SortField(FieldName, source, reverse));
        }
        public virtual SortField CreateSortField(bool reverse)
        {
            if (Converter == null || NativeSort)
            {
                return(new SortField(FieldName, SortField.STRING, reverse));
            }

            var propertyType = propertyInfo.PropertyType;

            FieldComparatorSource source;

            if (typeof(IComparable).IsAssignableFrom(propertyType))
            {
                source = new NonGenericConvertableFieldComparatorSource(propertyType, Converter);
            }
            else if (typeof(IComparable <>).MakeGenericType(propertyType).IsAssignableFrom(propertyType))
            {
                source = new GenericConvertableFieldComparatorSource(propertyType, Converter);
            }
            else
            {
                throw new NotSupportedException(string.Format("The type {0} does not implement IComparable or IComparable<T>. To use alphanumeric sorting, specify NativeSort=true on the mapping.",
                                                              propertyType));
            }

            return(new SortField(FieldName, source, reverse));
        }