diff --git a/DiscImageChef.CommonTypes/Partition.cs b/DiscImageChef.CommonTypes/Partition.cs
index 3a0dfc694..505a6c1db 100644
--- a/DiscImageChef.CommonTypes/Partition.cs
+++ b/DiscImageChef.CommonTypes/Partition.cs
@@ -30,12 +30,14 @@
// Copyright © 2011-2017 Natalia Portillo
// ****************************************************************************/
+using System;
+
namespace DiscImageChef.CommonTypes
{
///
/// Partition structure.
///
- public struct Partition
+ public struct Partition : IEquatable, IComparable
{
/// Partition number, 0-started
public ulong Sequence;
@@ -57,6 +59,71 @@ namespace DiscImageChef.CommonTypes
public ulong End { get { return Start + Length - 1; }}
/// Name of partition scheme that contains this partition
public string Scheme;
+
+ public bool Equals(Partition other)
+ {
+ return Start == other.Start && Length == other.Length;
+ }
+
+ public override bool Equals(Object obj)
+ {
+ if(obj == null || !(obj is Partition))
+ return false;
+ else
+ return Equals((Partition)obj);
+ }
+
+ public override int GetHashCode()
+ {
+ return Start.GetHashCode() + End.GetHashCode();
+ }
+
+ public int CompareTo(Partition other)
+ {
+ if(Start == other.Start && End == other.End)
+ return 0;
+
+ if(Start > other.Start || End > other.End)
+ return 1;
+
+ return -1;
+ }
+
+ // Define the equality operator.
+ public static bool operator ==(Partition operand1, Partition operand2)
+ {
+ return operand1.Equals(operand2);
+ }
+
+ // Define the inequality operator.
+ public static bool operator !=(Partition operand1, Partition operand2)
+ {
+ return !operand1.Equals(operand2);
+ }
+
+ // Define the is greater than operator.
+ public static bool operator >(Partition operand1, Partition operand2)
+ {
+ return operand1.CompareTo(operand2) == 1;
+ }
+
+ // Define the is less than operator.
+ public static bool operator <(Partition operand1, Partition operand2)
+ {
+ return operand1.CompareTo(operand2) == -1;
+ }
+
+ // Define the is greater than or equal to operator.
+ public static bool operator >=(Partition operand1, Partition operand2)
+ {
+ return operand1.CompareTo(operand2) >= 0;
+ }
+
+ // Define the is less than or equal to operator.
+ public static bool operator <=(Partition operand1, Partition operand2)
+ {
+ return operand1.CompareTo(operand2) <= 0;
+ }
}
}
diff --git a/DiscImageChef.Core/Partitions.cs b/DiscImageChef.Core/Partitions.cs
index 0d87f1eac..4e44af3d4 100644
--- a/DiscImageChef.Core/Partitions.cs
+++ b/DiscImageChef.Core/Partitions.cs
@@ -98,7 +98,7 @@ namespace DiscImageChef.Core
foreach(Partition child in childs)
{
- if(child.Start == father.Start)
+ if(child == father)
childPartitions.Add(father);
else
{