diff options
author | nulltoken <emeric.fermas@gmail.com> | 2012-02-24 17:05:23 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2012-02-25 22:08:48 +0400 |
commit | 318e7cad226d3eed5fc8829e757110494eaec7de (patch) | |
tree | 91ae07cc40539b74bb62efc4343e8487089a9ea0 /LibGit2Sharp | |
parent | 7f65f29bd9fa06e1b12a866eea9122a55ed2e4bc (diff) |
Make Remote IEquatable
Diffstat (limited to 'LibGit2Sharp')
-rw-r--r-- | LibGit2Sharp/Remote.cs | 61 |
1 files changed, 59 insertions, 2 deletions
diff --git a/LibGit2Sharp/Remote.cs b/LibGit2Sharp/Remote.cs index b4add398..07f7e6cb 100644 --- a/LibGit2Sharp/Remote.cs +++ b/LibGit2Sharp/Remote.cs @@ -1,10 +1,16 @@ -namespace LibGit2Sharp +using System; +using LibGit2Sharp.Core; + +namespace LibGit2Sharp { /// <summary> /// A remote repository whose branches are tracked. /// </summary> - public class Remote + public class Remote : IEquatable<Remote> { + private static readonly LambdaEqualityHelper<Remote> equalityHelper = + new LambdaEqualityHelper<Remote>(new Func<Remote, object>[] { x => x.Name, x => x.Url }); + /// <summary> /// Gets the alias of this remote repository. /// </summary> @@ -14,5 +20,56 @@ /// Gets the urls to use to communicate with this remote repository. /// </summary> public string Url { get; internal set; } + + /// <summary> + /// Determines whether the specified <see cref = "Object" /> is equal to the current <see cref = "Remote" />. + /// </summary> + /// <param name = "obj">The <see cref = "Object" /> to compare with the current <see cref = "Remote" />.</param> + /// <returns>True if the specified <see cref = "Object" /> is equal to the current <see cref = "Remote" />; otherwise, false.</returns> + public override bool Equals(object obj) + { + return Equals(obj as Remote); + } + + /// <summary> + /// Determines whether the specified <see cref = "Remote" /> is equal to the current <see cref = "Remote" />. + /// </summary> + /// <param name = "other">The <see cref = "Remote" /> to compare with the current <see cref = "Remote" />.</param> + /// <returns>True if the specified <see cref = "Remote" /> is equal to the current <see cref = "Remote" />; otherwise, false.</returns> + public bool Equals(Remote other) + { + return equalityHelper.Equals(this, other); + } + + /// <summary> + /// Returns the hash code for this instance. + /// </summary> + /// <returns>A 32-bit signed integer hash code.</returns> + public override int GetHashCode() + { + return equalityHelper.GetHashCode(this); + } + + /// <summary> + /// Tests if two <see cref = "Remote" /> are equal. + /// </summary> + /// <param name = "left">First <see cref = "Remote" /> to compare.</param> + /// <param name = "right">Second <see cref = "Remote" /> to compare.</param> + /// <returns>True if the two objects are equal; false otherwise.</returns> + public static bool operator ==(Remote left, Remote right) + { + return Equals(left, right); + } + + /// <summary> + /// Tests if two <see cref = "Remote" /> are different. + /// </summary> + /// <param name = "left">First <see cref = "Remote" /> to compare.</param> + /// <param name = "right">Second <see cref = "Remote" /> to compare.</param> + /// <returns>True if the two objects are different; false otherwise.</returns> + public static bool operator !=(Remote left, Remote right) + { + return !Equals(left, right); + } } } |