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)); }
/// <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); }
/// <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++; } }
/// <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; }
/// <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; }
/// <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; }
/// <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++; } }