diff options
author | nulltoken <emeric.fermas@gmail.com> | 2012-02-27 00:03:59 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2012-02-27 13:20:26 +0400 |
commit | 2194806398eec51c5a9dc14dd67a6c4934e2f340 (patch) | |
tree | eb771b2516e09d96524766af32edda6cc3948285 /LibGit2Sharp | |
parent | aa6f35c82db8120cb5dfcbe3019ac906089417bf (diff) |
Make RemoteCollection an IEnumerable<Remote>
Diffstat (limited to 'LibGit2Sharp')
-rw-r--r-- | LibGit2Sharp/Core/Libgit2UnsafeHelper.cs | 9 | ||||
-rw-r--r-- | LibGit2Sharp/Core/UnSafeNativeMethods.cs | 3 | ||||
-rw-r--r-- | LibGit2Sharp/RemoteCollection.cs | 36 |
3 files changed, 46 insertions, 2 deletions
diff --git a/LibGit2Sharp/Core/Libgit2UnsafeHelper.cs b/LibGit2Sharp/Core/Libgit2UnsafeHelper.cs index c725f005..62699ac1 100644 --- a/LibGit2Sharp/Core/Libgit2UnsafeHelper.cs +++ b/LibGit2Sharp/Core/Libgit2UnsafeHelper.cs @@ -14,6 +14,15 @@ namespace LibGit2Sharp.Core return BuildListOf(strArray); } + public static IList<string> ListAllRemoteNames(RepositorySafeHandle repo) + { + UnSafeNativeMethods.git_strarray strArray; + int res = UnSafeNativeMethods.git_remote_list(out strArray, repo); + Ensure.Success(res); + + return BuildListOf(strArray); + } + public static IList<string> ListAllTagNames(RepositorySafeHandle repo) { UnSafeNativeMethods.git_strarray strArray; diff --git a/LibGit2Sharp/Core/UnSafeNativeMethods.cs b/LibGit2Sharp/Core/UnSafeNativeMethods.cs index 0448b5c5..40d5b882 100644 --- a/LibGit2Sharp/Core/UnSafeNativeMethods.cs +++ b/LibGit2Sharp/Core/UnSafeNativeMethods.cs @@ -11,6 +11,9 @@ namespace LibGit2Sharp.Core public static extern int git_reference_listall(out git_strarray array, RepositorySafeHandle repo, GitReferenceType flags); [DllImport(libgit2)] + public static extern int git_remote_list(out git_strarray array, RepositorySafeHandle repo); + + [DllImport(libgit2)] public static extern int git_tag_list(out git_strarray array, RepositorySafeHandle repo); [DllImport(libgit2)] diff --git a/LibGit2Sharp/RemoteCollection.cs b/LibGit2Sharp/RemoteCollection.cs index b59625ae..e4c23688 100644 --- a/LibGit2Sharp/RemoteCollection.cs +++ b/LibGit2Sharp/RemoteCollection.cs @@ -1,8 +1,14 @@ -using LibGit2Sharp.Core; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using LibGit2Sharp.Core; namespace LibGit2Sharp { - public class RemoteCollection + /// <summary> + /// The collection of <see cref = "Remote" /> in a <see cref = "Repository" /> + /// </summary> + public class RemoteCollection : IEnumerable<Remote> { private readonly Repository repository; @@ -11,6 +17,11 @@ namespace LibGit2Sharp this.repository = repository; } + /// <summary> + /// Gets the <see cref = "Remote" /> with the specified name. + /// </summary> + /// <param name = "name">The name of the remote to retrieve.</param> + /// <returns>The retrived <see cref = "Remote" /> if it has been found, null otherwise.</returns> public Remote this[string name] { get { return RemoteForName(name); } @@ -39,5 +50,26 @@ namespace LibGit2Sharp return Remote.CreateFromPtr(handle); } } + + /// <summary> + /// Returns an enumerator that iterates through the collection. + /// </summary> + /// <returns>An <see cref = "IEnumerator{T}" /> object that can be used to iterate through the collection.</returns> + public IEnumerator<Remote> GetEnumerator() + { + return Libgit2UnsafeHelper + .ListAllRemoteNames(repository.Handle) + .Select(n => this[n]) + .GetEnumerator(); + } + + /// <summary> + /// Returns an enumerator that iterates through the collection. + /// </summary> + /// <returns>An <see cref = "IEnumerator" /> object that can be used to iterate through the collection.</returns> + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } } } |