blob: 33c300adaeb06972d9c5c4754bb3e75dc6a1f295 (
plain) (
blame)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
using System;
using System.Collections.Generic;
using Whoa;
namespace ShiftOS.Engine.ShiftFS
{
[Serializable]
public class ShiftTree : ShiftDirectory, IShiftNode
{
public ShiftTree(string name, char letter) : base(name)
{
Name = name;
Letter = letter;
}
public new IEnumerable<ShiftFile> Flatten()
{
foreach (var item in this)
{
switch (item)
{
case ShiftFile file:
yield return file;
break;
case ShiftDirectory dir:
foreach (var shiftNode in dir.Flatten())
{
yield return shiftNode;
}
break;
}
}
}
public new IEnumerable<ShiftDirectory> FlattenFolders()
{
foreach (var item in this)
{
if (!(item is ShiftDirectory dir)) continue;
yield return dir;
foreach (var subdir in dir.FlattenFolders())
{
yield return subdir;
}
}
}
public new string Name { get; set; }
public char Letter { get; }
public new string FullName => $@"{Name}:\";
public new ShiftDirectory Parent
{
get => null;
set => throw new InvalidOperationException("Cannot set parent of ShiftTree");
}
public new ShiftTree Drive => this;
}
}
|