1- using System . Collections ;
1+ using System ;
2+ using System . Collections ;
23using System . Collections . Generic ;
34using System . Diagnostics ;
45using System . Globalization ;
@@ -14,7 +15,9 @@ namespace LibGit2Sharp
1415 [ DebuggerDisplay ( "{DebuggerDisplay,nq}" ) ]
1516 public class RefSpecCollection : IEnumerable < RefSpec >
1617 {
17- readonly IList < RefSpec > refspecs ;
18+ readonly Remote remote ;
19+ readonly RemoteSafeHandle handle ;
20+ readonly Lazy < IList < RefSpec > > refspecs ;
1821
1922 /// <summary>
2023 /// Needed for mocking purposes.
@@ -26,7 +29,10 @@ internal RefSpecCollection(Remote remote, RemoteSafeHandle handle)
2629 {
2730 Ensure . ArgumentNotNull ( handle , "handle" ) ;
2831
29- refspecs = RetrieveRefSpecs ( remote , handle ) ;
32+ this . remote = remote ;
33+ this . handle = handle ;
34+
35+ refspecs = new Lazy < IList < RefSpec > > ( ( ) => RetrieveRefSpecs ( remote , handle ) ) ;
3036 }
3137
3238 static IList < RefSpec > RetrieveRefSpecs ( Remote remote , RemoteSafeHandle remoteHandle )
@@ -48,7 +54,7 @@ static IList<RefSpec> RetrieveRefSpecs(Remote remote, RemoteSafeHandle remoteHan
4854 /// <returns>An <see cref="IEnumerator{T}"/> object that can be used to iterate through the collection.</returns>
4955 public virtual IEnumerator < RefSpec > GetEnumerator ( )
5056 {
51- return refspecs . GetEnumerator ( ) ;
57+ return refspecs . Value . GetEnumerator ( ) ;
5258 }
5359
5460 /// <summary>
0 commit comments