5
5
namespace LibGit2Sharp
6
6
{
7
7
/// <summary>
8
- /// A reference to a <see cref= "Blob"/> known by the <see cref= "Index"/>.
8
+ /// A reference to a <see cref = "Blob" /> known by the <see cref = "Index" />.
9
9
/// </summary>
10
- public class IndexEntry
10
+ public class IndexEntry : IEquatable < IndexEntry >
11
11
{
12
+ private static readonly LambdaEqualityHelper < IndexEntry > equalityHelper =
13
+ new LambdaEqualityHelper < IndexEntry > ( new Func < IndexEntry , object > [ ] { x => x . Path , x => x . Id , x => x . State } ) ;
14
+
12
15
private Func < FileStatus > state ;
13
16
14
17
/// <summary>
15
- /// State of the version of the <see cref= "Blob"/> pointed at by this <see cref= "IndexEntry"/>,
16
- /// compared against the <see cref= "Blob"/> known from the <see cref= "Repository.Head"/> and the file in the working directory.
18
+ /// State of the version of the <see cref = "Blob" /> pointed at by this <see cref = "IndexEntry" />,
19
+ /// compared against the <see cref = "Blob" /> known from the <see cref = "Repository.Head" /> and the file in the working directory.
17
20
/// </summary>
18
21
public FileStatus State
19
22
{
@@ -26,7 +29,7 @@ public FileStatus State
26
29
public string Path { get ; private set ; }
27
30
28
31
/// <summary>
29
- /// Gets the id of the <see cref= "Blob"/> pointed at by this index entry.
32
+ /// Gets the id of the <see cref = "Blob" /> pointed at by this index entry.
30
33
/// </summary>
31
34
public ObjectId Id { get ; private set ; }
32
35
@@ -40,5 +43,56 @@ internal static IndexEntry CreateFromPtr(Repository repo, IntPtr ptr)
40
43
state = ( ) => repo . Index . RetrieveStatus ( entry . Path )
41
44
} ;
42
45
}
46
+
47
+ /// <summary>
48
+ /// Determines whether the specified <see cref = "Object" /> is equal to the current <see cref = "IndexEntry" />.
49
+ /// </summary>
50
+ /// <param name = "obj">The <see cref = "Object" /> to compare with the current <see cref = "IndexEntry" />.</param>
51
+ /// <returns>True if the specified <see cref = "Object" /> is equal to the current <see cref = "IndexEntry" />; otherwise, false.</returns>
52
+ public override bool Equals ( object obj )
53
+ {
54
+ return Equals ( obj as IndexEntry ) ;
55
+ }
56
+
57
+ /// <summary>
58
+ /// Determines whether the specified <see cref = "IndexEntry" /> is equal to the current <see cref = "IndexEntry" />.
59
+ /// </summary>
60
+ /// <param name = "other">The <see cref = "IndexEntry" /> to compare with the current <see cref = "IndexEntry" />.</param>
61
+ /// <returns>True if the specified <see cref = "IndexEntry" /> is equal to the current <see cref = "IndexEntry" />; otherwise, false.</returns>
62
+ public bool Equals ( IndexEntry other )
63
+ {
64
+ return equalityHelper . Equals ( this , other ) ;
65
+ }
66
+
67
+ /// <summary>
68
+ /// Returns the hash code for this instance.
69
+ /// </summary>
70
+ /// <returns>A 32-bit signed integer hash code.</returns>
71
+ public override int GetHashCode ( )
72
+ {
73
+ return equalityHelper . GetHashCode ( this ) ;
74
+ }
75
+
76
+ /// <summary>
77
+ /// Tests if two <see cref = "IndexEntry" /> are equal.
78
+ /// </summary>
79
+ /// <param name = "left">First <see cref = "IndexEntry" /> to compare.</param>
80
+ /// <param name = "right">Second <see cref = "IndexEntry" /> to compare.</param>
81
+ /// <returns>True if the two objects are equal; false otherwise.</returns>
82
+ public static bool operator == ( IndexEntry left , IndexEntry right )
83
+ {
84
+ return Equals ( left , right ) ;
85
+ }
86
+
87
+ /// <summary>
88
+ /// Tests if two <see cref = "IndexEntry" /> are different.
89
+ /// </summary>
90
+ /// <param name = "left">First <see cref = "IndexEntry" /> to compare.</param>
91
+ /// <param name = "right">Second <see cref = "IndexEntry" /> to compare.</param>
92
+ /// <returns>True if the two objects are different; false otherwise.</returns>
93
+ public static bool operator != ( IndexEntry left , IndexEntry right )
94
+ {
95
+ return ! Equals ( left , right ) ;
96
+ }
43
97
}
44
98
}
0 commit comments