Пример #1
0
 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");
     }
 }
Пример #2
0
 public Purchase(File file, DateTime endTime) {
     this.file = file;
     this.endTime = endTime;
 }
Пример #3
0
 protected static void ByRating(File[] files) {
     Array.Sort(files, (f1, f2) => -1 * f1.AverageRating.CompareTo(f2.AverageRating)); // *-1 to order descending
 }
Пример #4
0
 protected static void ByViews(File[] files) {
     Array.Sort(files, (f1, f2) => -1 * f1.ViewCount.CompareTo(f2.ViewCount));  // *-1 to order descending
     
 }
Пример #5
0
 protected static void ByRentPrice(File[] files) {
     Array.Sort(files, (f1, f2) => f1.RentPrice.CompareTo(f2.RentPrice));
 }
Пример #6
0
 protected static void ByYear(File[] files) {
     Array.Sort(files, (f1, f2) => f1.Year.CompareTo(f2.Year));
 }
Пример #7
0
 protected static void ByGenre(File[] files) {
     Array.Sort(files, (f1, f2) => f1.Genres[0].CompareTo(f2.Genres[0])); //This is a pretty useless sort.
 }
Пример #8
0
 protected static void ByDescription(File[] files) {
     Array.Sort(files, (f1, f2) => f1.Description.CompareTo(f2.Description));
 }
Пример #9
0
/*        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));
        }