예제 #1
0
 public static IOrderedQueryable <T> Sort <T>(this IQueryable <T> source, ISortDefinition <T> sort)
 {
     //Contract.Requires( source != null );
     //Contract.Requires( sort != null );
     //Contract.Ensures( //Contract.Result<IOrderedQueryable<T>>() != null );
     return(sort.Apply(source));
 }
예제 #2
0
        /// <summary>
        /// Overrides the default <see cref="System.Object.Equals(object)"/> method
        /// </summary>
        /// <param name="obj">
        /// The object to test against this instance for equality.
        /// </param>
        /// <returns>
        /// True if the supplied <paramref name="obj"/> is equal to this instance.
        /// </returns>
        public override bool Equals(object obj)
        {
            if (!(obj is ISortDefinition))
            {
                return(false);
            }
            ISortDefinition sd = (ISortDefinition)obj;

            return(this.Property.Equals(sd.Property) &&
                   this.Ascending == sd.Ascending && this.IgnoreCase == sd.IgnoreCase);
        }
        public void CanGetSortDefinition()
        {
            ISortDefinition definition = new MutableSortDefinition("Age", false, true);

            PropertyComparator cmp            = new PropertyComparator(definition);
            ISortDefinition    sortDefinition = cmp.SortDefinition;

            Assert.AreSame(definition, sortDefinition);
            Assert.AreEqual(definition.Property, sortDefinition.Property);
            Assert.AreEqual(definition.Ascending, sortDefinition.Ascending);
            Assert.AreEqual(definition.IgnoreCase, sortDefinition.IgnoreCase);
        }
예제 #4
0
        /// <summary>
        /// Sort the given <see cref="System.Collections.IList"/> according to the
        /// given sort definition.
        /// </summary>
        /// <param name="source">
        /// The <see cref="System.Collections.IList"/> to be sorted.
        /// </param>
        /// <param name="sortDefinition">The parameters to sort by.</param>
        /// <exception cref="Spring.Objects.ObjectsException">
        /// In the case of a missing property name.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        /// If the supplied <paramref name="sortDefinition"/> is <cref lang="null"/>.
        /// </exception>
        public static void Sort(IList source, ISortDefinition sortDefinition)
        {
//            ArrayList.Adapter(source).Sort(new PropertyComparator(sortDefinition));
            ICollection coll  = CollectionUtils.StableSort(source, new PropertyComparator(sortDefinition));
            int         index = 0;
            IEnumerator it    = coll.GetEnumerator();

            while (it.MoveNext())
            {
                source[index] = it.Current;
                index++;
            }
        }
예제 #5
0
 /// <summary>
 /// Creates a new instance of the
 /// <see cref="Spring.Objects.Support.MutableSortDefinition"/> class using
 /// the specified <see cref="Spring.Objects.Support.ISortDefinition"/>.
 /// </summary>
 /// <param name="source">
 /// The <see cref="Spring.Objects.Support.ISortDefinition"/> to use
 /// as a source for initial property values.
 /// </param>
 public MutableSortDefinition(ISortDefinition source)
 {
     this._property   = source.Property;
     this._ignoreCase = source.IgnoreCase;
     this._ascending  = source.Ascending;
 }
		/// <summary>
        /// Creates a new instance of the
        /// <see cref="Spring.Objects.Support.MutableSortDefinition"/> class using
        /// the specified <see cref="Spring.Objects.Support.ISortDefinition"/>.
		/// </summary>
		/// <param name="source">
		/// The <see cref="Spring.Objects.Support.ISortDefinition"/> to use
		/// as a source for initial property values.
		/// </param>
		public MutableSortDefinition (ISortDefinition source)
		{
			this._property = source.Property;
			this._ignoreCase = source.IgnoreCase;
			this._ascending = source.Ascending;
		}
예제 #7
0
 /// <summary>
 /// Creates a new instance of the
 /// <see cref="Spring.Objects.Support.PropertyComparator"/> class.
 /// </summary>
 /// <param name="definition">
 /// The <see cref="Spring.Objects.Support.ISortDefinition"/> to use for any
 /// sorting.
 /// </param>
 /// <exception cref="System.ArgumentNullException">
 /// If the supplied <paramref name="definition"/> is <cref lang="null"/>.
 /// </exception>
 public PropertyComparator(ISortDefinition definition)
 {
     AssertUtils.ArgumentNotNull(definition, "definition");
     this.sortDefinition = definition;
 }
예제 #8
0
 /// <summary>
 /// Creates a new instance of the
 /// <see cref="Spring.Objects.Support.PropertyComparator"/> class.
 /// </summary>
 /// <param name="definition">
 /// The <see cref="Spring.Objects.Support.ISortDefinition"/> to use for any
 /// sorting.
 /// </param>
 /// <exception cref="System.ArgumentNullException">
 /// If the supplied <paramref name="definition"/> is <cref lang="null"/>.
 /// </exception>
 public PropertyComparator(ISortDefinition definition)
 {
     AssertUtils.ArgumentNotNull(definition, "definition");
     this.sortDefinition = definition;
 }
예제 #9
0
        /// <summary>
        /// Sort the given <see cref="System.Collections.IList"/> according to the
        /// given sort definition.
        /// </summary>
        /// <param name="source">
        /// The <see cref="System.Collections.IList"/> to be sorted.
        /// </param>
        /// <param name="sortDefinition">The parameters to sort by.</param>
        /// <exception cref="Spring.Objects.ObjectsException">
        /// In the case of a missing property name.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        /// If the supplied <paramref name="sortDefinition"/> is <cref lang="null"/>.
        /// </exception>
        public static void Sort(IList source, ISortDefinition sortDefinition)
        {
//            ArrayList.Adapter(source).Sort(new PropertyComparator(sortDefinition));
            ICollection coll = CollectionUtils.StableSort(source, new PropertyComparator(sortDefinition));
            int index = 0;
            IEnumerator it = coll.GetEnumerator();
            while(it.MoveNext())
            {
                source[index] = it.Current;
                index++;
            }
        }