using System; using System.Diagnostics; using System.Globalization; using LibGit2Sharp.Core; using LibGit2Sharp.Core.Handles; namespace LibGit2Sharp { /// /// A note, attached to a given . /// [DebuggerDisplay("{DebuggerDisplay,nq}")] public class Note : IEquatable { /// /// Needed for mocking purposes. /// protected Note() { } private Note(ObjectId blobId, string message, ObjectId targetObjectId, string @namespace) { BlobId = blobId; Namespace = @namespace; Message = message; TargetObjectId = targetObjectId; } /// /// The of the blob containing the note message. /// public virtual ObjectId BlobId { get; private set; } /// /// The message. /// public virtual string Message { get; private set; } /// /// The namespace with which this note is associated. /// This is the abbreviated namespace (e.g.: commits), and not the canonical namespace (e.g.: refs/notes/commits). /// public virtual string Namespace { get; private set; } /// /// The of the target object. /// public virtual ObjectId TargetObjectId { get; private set; } internal static Note BuildFromPtr(NoteSafeHandle note, string @namespace, ObjectId targetObjectId) { ObjectId oid = Proxy.git_note_id(note); string message = Proxy.git_note_message(note); return new Note(oid, message, targetObjectId, @namespace); } private static readonly LambdaEqualityHelper equalityHelper = new LambdaEqualityHelper(x => x.BlobId, x => x.TargetObjectId, x => x.Namespace); /// /// 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 Note); } /// /// 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(Note 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 ==(Note left, Note 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 !=(Note left, Note right) { return !Equals(left, right); } private string DebuggerDisplay { get { return string.Format(CultureInfo.InvariantCulture, "Target \"{0}\", Namespace \"{1}\": {2}", TargetObjectId.ToString(7), Namespace, Message); } } } }