Skip to content

Commit 0e1b72c

Browse files
committed
[Watcher] Implement IEquatable
1 parent 1b952a7 commit 0e1b72c

File tree

1 file changed

+72
-4
lines changed

1 file changed

+72
-4
lines changed

src/redmine-net-api/Types/Watcher.cs

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
Copyright 2011 - 2025 Adrian Popescu
33
44
Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,6 +18,7 @@ limitations under the License.
1818
using System.Diagnostics;
1919
using System.Globalization;
2020
using System.Xml.Serialization;
21+
using Redmine.Net.Api.Internals;
2122

2223
namespace Redmine.Net.Api.Types
2324
{
@@ -26,7 +27,8 @@ namespace Redmine.Net.Api.Types
2627
/// </summary>
2728
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
2829
[XmlRoot(RedmineKeys.USER)]
29-
public sealed class Watcher : Identifiable<Watcher>
30+
public sealed class Watcher : IdentifiableName
31+
,IEquatable<Watcher>
3032
,ICloneable<Watcher>
3133
,IValue
3234
{
@@ -47,16 +49,82 @@ public sealed class Watcher : Identifiable<Watcher>
4749
{
4850
if (resetId)
4951
{
50-
return new Watcher();
52+
return new Watcher()
53+
{
54+
Name = Name
55+
};
5156
}
5257
return new Watcher
5358
{
54-
Id = Id
59+
Id = Id,
60+
Name = Name
5561
};
5662
}
5763

5864
#endregion
5965

66+
#region Implementation of IEquatable<IdentifiableName>
67+
/// <summary>
68+
///
69+
/// </summary>
70+
/// <param name="other"></param>
71+
/// <returns></returns>
72+
public bool Equals(Watcher other)
73+
{
74+
if (other == null) return false;
75+
return Id == other.Id && string.Equals(Name, other.Name, StringComparison.Ordinal);
76+
}
77+
78+
/// <summary>
79+
///
80+
/// </summary>
81+
/// <param name="obj"></param>
82+
/// <returns></returns>
83+
public override bool Equals(object obj)
84+
{
85+
if (ReferenceEquals(null, obj)) return false;
86+
if (ReferenceEquals(this, obj)) return true;
87+
if (obj.GetType() != GetType()) return false;
88+
return Equals(obj as Watcher);
89+
}
90+
91+
/// <summary>
92+
///
93+
/// </summary>
94+
/// <returns></returns>
95+
public override int GetHashCode()
96+
{
97+
unchecked
98+
{
99+
var hashCode = base.GetHashCode();
100+
hashCode = HashCodeHelper.GetHashCode(Name, hashCode);
101+
return hashCode;
102+
}
103+
}
104+
105+
/// <summary>
106+
///
107+
/// </summary>
108+
/// <param name="left"></param>
109+
/// <param name="right"></param>
110+
/// <returns></returns>
111+
public static bool operator ==(Watcher left, Watcher right)
112+
{
113+
return Equals(left, right);
114+
}
115+
116+
/// <summary>
117+
///
118+
/// </summary>
119+
/// <param name="left"></param>
120+
/// <param name="right"></param>
121+
/// <returns></returns>
122+
public static bool operator !=(Watcher left, Watcher right)
123+
{
124+
return !Equals(left, right);
125+
}
126+
#endregion
127+
60128
/// <summary>
61129
///
62130
/// </summary>

0 commit comments

Comments
 (0)