-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTreeSortService.cs
More file actions
47 lines (42 loc) · 1.83 KB
/
Copy pathTreeSortService.cs
File metadata and controls
47 lines (42 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Linq;
namespace c2flux
{
public static class TreeSortService
{
public static void Sort(FileSystemEntry entry, TreeSortMode mode)
{
if (entry == null)
return;
foreach (FileSystemEntry child in entry.Children.Where(child => child.IsDirectory))
{
Sort(child, mode);
}
System.Collections.Generic.IEnumerable<FileSystemEntry> ordered = entry.Children;
switch (mode)
{
case TreeSortMode.SizeAscending:
ordered = entry.Children.OrderBy(child => child.SizeBytes).ThenBy(child => child.Name);
break;
case TreeSortMode.NameAscending:
ordered = entry.Children.OrderBy(child => child.Name, StringComparer.CurrentCultureIgnoreCase);
break;
case TreeSortMode.NameDescending:
ordered = entry.Children.OrderByDescending(child => child.Name, StringComparer.CurrentCultureIgnoreCase);
break;
case TreeSortMode.DateDescending:
ordered = entry.Children.OrderByDescending(child => child.LastWriteTimeUtc).ThenBy(child => child.Name);
break;
case TreeSortMode.DateAscending:
ordered = entry.Children.OrderBy(child => child.LastWriteTimeUtc).ThenBy(child => child.Name);
break;
default:
ordered = entry.Children.OrderByDescending(child => child.SizeBytes).ThenBy(child => child.Name);
break;
}
System.Collections.Generic.List<FileSystemEntry> sorted = ordered.ToList();
entry.Children.Clear();
entry.Children.AddRange(sorted);
}
}
}