public int CompareTo(MyFile fileToCompare, Enums.ComparisonType comparisonType = Enums.ComparisonType.DateOfCreation) { if (comparisonType == Enums.ComparisonType.Size) { if (this.Size > fileToCompare.Size) { return(1); } else if (this.Size < fileToCompare.Size) { return(-1); } else if (this.Size == fileToCompare.Size) { return(0); } } else if (comparisonType == Enums.ComparisonType.DateOfCreation) { if (DateTime.Compare(this.CreationDate, fileToCompare.CreationDate) > 0) { return(1); } else if (DateTime.Compare(this.CreationDate, fileToCompare.CreationDate) < 0) { return(-1); } else if (DateTime.Compare(this.CreationDate, fileToCompare.CreationDate) == 0) { return(0); } } throw new ArgumentOutOfRangeException("Wrong comparison type"); }
public int CompareTo(MyDir a, Enums.ComparisonType C = Enums.ComparisonType.Size) { if (C == Enums.ComparisonType.Size) { if (this.Size > a.Size) { return(1); } else if (this.Size < a.Size) { return(-1); } else if (this.Size == a.Size) { return(0); } } else if (C == Enums.ComparisonType.DateOfCreation) { if (DateTime.Compare(this.CreationDate, a.CreationDate) > 0) { return(1); } else if (DateTime.Compare(this.CreationDate, a.CreationDate) < 0) { return(-1); } else if (DateTime.Compare(this.CreationDate, a.CreationDate) == 0) { return(0); } } throw new ArgumentOutOfRangeException("Wrong comparison type"); }
public static T Max <T>(IEnumerable <T> x, Enums.ComparisonType compType) where T : IBetterComparable <T> { T w = x.First(); foreach (T s in x) { if (w.CompareTo(s, compType) == -1) { w = s; } } return(w); }
public MyDir MaxDir(Enums.ComparisonType compType) { IEnumerable <MyDir> a = this.Content.OfType <MyDir>(); MyDir max = Program.Max(a, compType); foreach (MyDir s in a) { MyDir x = s.MaxDir(compType); if (x != null && x.CompareTo(max, compType) == 1) { max = x; } } return(max); }
public MyFile MaxFile(Enums.ComparisonType compType) { IEnumerable <MyDir> b = this.Content.OfType <MyDir>(); IEnumerable <MyFile> a = this.Content.OfType <MyFile>(); MyFile max = Program.Max(a, compType); foreach (MyDir s in b) { MyFile x = s.MaxFile(compType); if (x != null && max != null) { if (x.CompareTo(max, compType) == 1) { max = x; } } else if (max == null) { max = x; } } return(max); }
public static IEnumerable <FileOnList> GetDirectoryContent(string directoryPath, Enums.ComparisonType compType = Enums.ComparisonType.Default) { MyDir tmp = new MyDir(directoryPath, true); List <FileOnList> discObjList = new List <FileOnList>(); foreach (DiscObj discObj in tmp.Content) { discObjList.Add(new FileOnList(discObj.Path)); } return(discObjList); }