Skip to content

Commit a736cc3

Browse files
committed
Added equality and inequality operators
1 parent 585cedd commit a736cc3

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

src/Synercoding.Primitives/Point.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,23 @@ public bool Equals(Point other)
8989
/// <inheritdoc />
9090
public override string ToString()
9191
=> $"X: {X}, Y: {Y}";
92+
93+
/// <summary>
94+
/// Returns a value that indicates whether two specified <see cref="Point"/> values are equal.
95+
/// </summary>
96+
/// <param name="left">The first value to compare.</param>
97+
/// <param name="right">The second value to compare.</param>
98+
/// <returns>true if left and right are equal; otherwise, false.</returns>
99+
public static bool operator ==(Point left, Point right)
100+
=> left.Equals(right);
101+
102+
/// <summary>
103+
/// Returns a value that indicates whether two specified <see cref="Point"/> values are not equal.
104+
/// </summary>
105+
/// <param name="left">The first value to compare.</param>
106+
/// <param name="right">The second value to compare.</param>
107+
/// <returns>true if left and right are not equal; otherwise, false.</returns>
108+
public static bool operator !=(Point left, Point right)
109+
=> !( left == right );
92110
}
93111
}

src/Synercoding.Primitives/Rectangle.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,23 @@ public bool Equals(Rectangle other)
163163
/// <inheritdoc/>
164164
public override string ToString()
165165
=> $"LLX {LLX}, LLY {LLY}, URX {URX}, URY {URY}";
166+
167+
/// <summary>
168+
/// Returns a value that indicates whether two specified <see cref="Rectangle"/> values are equal.
169+
/// </summary>
170+
/// <param name="left">The first value to compare.</param>
171+
/// <param name="right">The second value to compare.</param>
172+
/// <returns>true if left and right are equal; otherwise, false.</returns>
173+
public static bool operator ==(Rectangle left, Rectangle right)
174+
=> left.Equals(right);
175+
176+
/// <summary>
177+
/// Returns a value that indicates whether two specified <see cref="Rectangle"/> values are not equal.
178+
/// </summary>
179+
/// <param name="left">The first value to compare.</param>
180+
/// <param name="right">The second value to compare.</param>
181+
/// <returns>true if left and right are not equal; otherwise, false.</returns>
182+
public static bool operator !=(Rectangle left, Rectangle right)
183+
=> !( left == right );
166184
}
167185
}

src/Synercoding.Primitives/Size.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,23 @@ public bool Equals(Size other)
101101
/// <inheritdoc/>
102102
public override string ToString()
103103
=> $"W: {Width}, H: {Height}";
104+
105+
/// <summary>
106+
/// Returns a value that indicates whether two specified <see cref="Size"/> values are equal.
107+
/// </summary>
108+
/// <param name="left">The first value to compare.</param>
109+
/// <param name="right">The second value to compare.</param>
110+
/// <returns>true if left and right are equal; otherwise, false.</returns>
111+
public static bool operator ==(Size left, Size right)
112+
=> left.Equals(right);
113+
114+
/// <summary>
115+
/// Returns a value that indicates whether two specified <see cref="Size"/> values are not equal.
116+
/// </summary>
117+
/// <param name="left">The first value to compare.</param>
118+
/// <param name="right">The second value to compare.</param>
119+
/// <returns>true if left and right are not equal; otherwise, false.</returns>
120+
public static bool operator !=(Size left, Size right)
121+
=> !( left == right );
104122
}
105123
}

src/Synercoding.Primitives/Spacing.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,23 @@ public bool Equals(Spacing other)
121121
&& a.Right == b.Right
122122
&& a.Bottom == b.Bottom;
123123
}
124+
125+
/// <summary>
126+
/// Returns a value that indicates whether two specified <see cref="Spacing"/> values are equal.
127+
/// </summary>
128+
/// <param name="left">The first value to compare.</param>
129+
/// <param name="right">The second value to compare.</param>
130+
/// <returns>true if left and right are equal; otherwise, false.</returns>
131+
public static bool operator ==(Spacing left, Spacing right)
132+
=> left.Equals(right);
133+
134+
/// <summary>
135+
/// Returns a value that indicates whether two specified <see cref="Spacing"/> values are not equal.
136+
/// </summary>
137+
/// <param name="left">The first value to compare.</param>
138+
/// <param name="right">The second value to compare.</param>
139+
/// <returns>true if left and right are not equal; otherwise, false.</returns>
140+
public static bool operator !=(Spacing left, Spacing right)
141+
=> !( left == right );
124142
}
125143
}

0 commit comments

Comments
 (0)