-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItemComparer.cs
68 lines (58 loc) · 1.58 KB
/
ItemComparer.cs
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
67
68
/**
* Created by SharpDevelop.
* User: omggomb
* Date: 04.06.2014
* Time: 22:35
*/
using System;
namespace ExplorerTreeView
{
/// <summary>
/// Class used to compare two tree items against each other.
/// Needed since live sorting is updating according to a atrribute of the items, as which
/// this class will serve
/// </summary>
public class ItemComparer : IComparable
{
#region Attributes
/// <summary>
/// The name that is used to identify a tree item.
/// It should always be the name of the file or folder that is represented
/// by the tree view item.
/// </summary>
public string sIdentificationName;
/// <summary>
/// Is the tree item a directory?
/// </summary>
public bool bIsDirectory;
#endregion
#region CTOR
public ItemComparer()
{
sIdentificationName = "";
bIsDirectory = false;
}
#endregion
#region Public methods
/// <summary>
/// Compares the given object with this one.
/// Directories go before files.
/// If both are of the same type (dir or file) the identification name is compared alphabetically.
/// </summary>
/// <param name="compareToThis"></param>
/// <returns></returns>
public int CompareTo(object compareToThis)
{
var compareCast = compareToThis as ItemComparer;
if (compareCast == null)
return 1;
if (bIsDirectory == true && compareCast.bIsDirectory == false)
return -1;
else if (bIsDirectory == false && compareCast.bIsDirectory == true)
return 1;
else
return sIdentificationName.CompareTo(compareCast.sIdentificationName);
}
#endregion
}
}