using System.Collections; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Globalization; using LibGit2Sharp.Core; using LibGit2Sharp.Core.Handles; namespace LibGit2Sharp { /// /// The collection of s in a /// [DebuggerDisplay("{DebuggerDisplay,nq}")] public class RefSpecCollection : IEnumerable { readonly IList refspecs; /// /// Needed for mocking purposes. /// protected RefSpecCollection() { } internal RefSpecCollection(RemoteSafeHandle handle) { Ensure.ArgumentNotNull(handle, "handle"); refspecs = RetrieveRefSpecs(handle); } static IList RetrieveRefSpecs(RemoteSafeHandle remoteHandle) { int count = Proxy.git_remote_refspec_count(remoteHandle); List refSpecs = new List(); for (int i = 0; i < count; i++) { using (GitRefSpecHandle handle = Proxy.git_remote_get_refspec(remoteHandle, i)) { refSpecs.Add(RefSpec.BuildFromPtr(handle)); } } return refSpecs; } /// /// Returns an enumerator that iterates through the collection. /// /// An object that can be used to iterate through the collection. public virtual IEnumerator GetEnumerator() { return refspecs.GetEnumerator(); } /// /// Returns an enumerator that iterates through the collection. /// /// An object that can be used to iterate through the collection. IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } private string DebuggerDisplay { get { return string.Format(CultureInfo.InvariantCulture, "Count = {0}", this.Count()); } } } }