using System;
using System.Diagnostics;
using LibGit2Sharp.Core;
namespace LibGit2Sharp
{
///
/// Holds the calculated status of a particular file at a particular instant.
///
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class StatusEntry : IEquatable
{
private readonly string filePath;
private readonly FileStatus state;
private static readonly LambdaEqualityHelper equalityHelper =
new LambdaEqualityHelper(x => x.FilePath, x => x.State);
///
/// Needed for mocking purposes.
///
protected StatusEntry()
{ }
internal StatusEntry(string filePath, FileStatus state)
{
this.filePath = filePath;
this.state = state;
}
///
/// Gets the of the file.
///
public virtual FileStatus State
{
get { return state; }
}
///
/// Gets the relative filepath to the working directory of the file.
///
public virtual string FilePath
{
get { return filePath; }
}
///
/// Determines whether the specified is equal to the current .
///
/// The to compare with the current .
/// True if the specified is equal to the current ; otherwise, false.
public override bool Equals(object obj)
{
return Equals(obj as StatusEntry);
}
///
/// Determines whether the specified is equal to the current .
///
/// The to compare with the current .
/// True if the specified is equal to the current ; otherwise, false.
public bool Equals(StatusEntry other)
{
return equalityHelper.Equals(this, other);
}
///
/// Returns the hash code for this instance.
///
/// A 32-bit signed integer hash code.
public override int GetHashCode()
{
return equalityHelper.GetHashCode(this);
}
///
/// Tests if two are equal.
///
/// First to compare.
/// Second to compare.
/// True if the two objects are equal; false otherwise.
public static bool operator ==(StatusEntry left, StatusEntry right)
{
return Equals(left, right);
}
///
/// Tests if two are different.
///
/// First to compare.
/// Second to compare.
/// True if the two objects are different; false otherwise.
public static bool operator !=(StatusEntry left, StatusEntry right)
{
return !Equals(left, right);
}
private string DebuggerDisplay
{
get { return string.Format("{0}: {1}", State, FilePath); }
}
}
}