public static void SortBy(File[] files, String property) { //should probably be done with enums, or by a completely different pattern (visitor?) switch (property.ToLower()) { case "title": ByTitle(files); break; case "description" : ByDescription(files); break; case "genre": ByGenre(files); break; case "release": case "year": ByYear(files); break; case "averagerating": case "averageratings": case "avgrating": case "avgratings": ByRating(files); break; case "views": case "view": case "viewcount": case "viewcounts": ByViews(files); break; default: throw new ArgumentException(property + " is undefined"); } }
public Purchase(File file, DateTime endTime) { this.file = file; this.endTime = endTime; }
protected static void ByRating(File[] files) { Array.Sort(files, (f1, f2) => -1 * f1.AverageRating.CompareTo(f2.AverageRating)); // *-1 to order descending }
protected static void ByViews(File[] files) { Array.Sort(files, (f1, f2) => -1 * f1.ViewCount.CompareTo(f2.ViewCount)); // *-1 to order descending }
protected static void ByRentPrice(File[] files) { Array.Sort(files, (f1, f2) => f1.RentPrice.CompareTo(f2.RentPrice)); }
protected static void ByYear(File[] files) { Array.Sort(files, (f1, f2) => f1.Year.CompareTo(f2.Year)); }
protected static void ByGenre(File[] files) { Array.Sort(files, (f1, f2) => f1.Genres[0].CompareTo(f2.Genres[0])); //This is a pretty useless sort. }
protected static void ByDescription(File[] files) { Array.Sort(files, (f1, f2) => f1.Description.CompareTo(f2.Description)); }
/* private static Sorter instance; private Sorter() { } public static Sorter Instance { get { if (instance == null) { instance = new Sorter(); } return instance; } }*/ protected static void ByTitle(File[] files) { Array.Sort(files, (f1, f2) => f1.Title.CompareTo(f2.Title)); }