1- using System . Diagnostics ;
2- using System . Runtime . CompilerServices ;
3-
41using Ramstack . Globbing . Traversal ;
52
63namespace Ramstack . FileSystem ;
@@ -121,16 +118,7 @@ public IAsyncEnumerable<VirtualDirectory> GetDirectoriesAsync(CancellationToken
121118 public IAsyncEnumerable < VirtualNode > GetFileNodesAsync ( string [ ] patterns , string [ ] ? excludes , CancellationToken cancellationToken = default )
122119 {
123120 ArgumentNullException . ThrowIfNull ( patterns ) ;
124-
125- return new FileTreeAsyncEnumerable < VirtualNode , VirtualNode > ( this , cancellationToken )
126- {
127- Patterns = patterns ,
128- Excludes = excludes ?? [ ] ,
129- FileNameSelector = node => node . FullName ,
130- ShouldRecursePredicate = node => node is VirtualDirectory ,
131- ChildrenSelector = ( node , token ) => ( ( VirtualDirectory ) node ) . GetFileNodesCoreAsync ( token ) ,
132- ResultSelector = node => node
133- } ;
121+ return GetFileNodesCoreAsync ( patterns , excludes , cancellationToken ) ;
134122 }
135123
136124 /// <summary>
@@ -146,17 +134,7 @@ public IAsyncEnumerable<VirtualNode> GetFileNodesAsync(string[] patterns, string
146134 public IAsyncEnumerable < VirtualFile > GetFilesAsync ( string [ ] patterns , string [ ] ? excludes , CancellationToken cancellationToken = default )
147135 {
148136 ArgumentNullException . ThrowIfNull ( patterns ) ;
149-
150- return new FileTreeAsyncEnumerable < VirtualNode , VirtualFile > ( this , cancellationToken )
151- {
152- Patterns = patterns ,
153- Excludes = excludes ?? [ ] ,
154- FileNameSelector = node => node . FullName ,
155- ShouldIncludePredicate = node => node is VirtualFile ,
156- ShouldRecursePredicate = node => node is VirtualDirectory ,
157- ChildrenSelector = ( node , token ) => ( ( VirtualDirectory ) node ) . GetFileNodesCoreAsync ( token ) ,
158- ResultSelector = node => ( VirtualFile ) node
159- } ;
137+ return GetFilesCoreAsync ( patterns , excludes , cancellationToken ) ;
160138 }
161139
162140 /// <summary>
@@ -172,17 +150,7 @@ public IAsyncEnumerable<VirtualFile> GetFilesAsync(string[] patterns, string[]?
172150 public IAsyncEnumerable < VirtualDirectory > GetDirectoriesAsync ( string [ ] patterns , string [ ] ? excludes , CancellationToken cancellationToken = default )
173151 {
174152 ArgumentNullException . ThrowIfNull ( patterns ) ;
175-
176- return new FileTreeAsyncEnumerable < VirtualNode , VirtualDirectory > ( this , cancellationToken )
177- {
178- Patterns = patterns ,
179- Excludes = excludes ?? [ ] ,
180- FileNameSelector = node => node . FullName ,
181- ShouldIncludePredicate = node => node is VirtualDirectory ,
182- ShouldRecursePredicate = node => node is VirtualDirectory ,
183- ChildrenSelector = ( node , token ) => ( ( VirtualDirectory ) node ) . GetFileNodesCoreAsync ( token ) ,
184- ResultSelector = node => ( VirtualDirectory ) node
185- } ;
153+ return GetDirectoriesCoreAsync ( patterns , excludes , cancellationToken ) ;
186154 }
187155
188156 /// <summary>
@@ -243,4 +211,75 @@ protected virtual async IAsyncEnumerable<VirtualDirectory> GetDirectoriesCoreAsy
243211 yield return directory ;
244212 }
245213 }
214+
215+ /// <summary>
216+ /// Core implementation for asynchronously returning an async-enumerable collection of file nodes (both directories and files)
217+ /// within the current directory that match any of the specified glob patterns.
218+ /// </summary>
219+ /// <param name="patterns">An array of glob patterns to match against the names of file nodes.</param>
220+ /// <param name="excludes">An optional array of glob patterns to exclude file nodes.</param>
221+ /// <param name="cancellationToken">An optional cancellation token to cancel the operation.</param>
222+ /// <returns>
223+ /// An async-enumerable collection of <see cref="VirtualNode"/> instances.
224+ /// </returns>
225+ protected virtual IAsyncEnumerable < VirtualNode > GetFileNodesCoreAsync ( string [ ] patterns , string [ ] ? excludes , CancellationToken cancellationToken )
226+ {
227+ return new FileTreeAsyncEnumerable < VirtualNode , VirtualNode > ( this , cancellationToken )
228+ {
229+ Patterns = patterns ,
230+ Excludes = excludes ?? [ ] ,
231+ FileNameSelector = node => node . Name ,
232+ ShouldRecursePredicate = node => node is VirtualDirectory ,
233+ ChildrenSelector = ( node , token ) => ( ( VirtualDirectory ) node ) . GetFileNodesCoreAsync ( token ) ,
234+ ResultSelector = node => node
235+ } ;
236+ }
237+
238+ /// <summary>
239+ /// Core implementation for asynchronously returning an async-enumerable collection of files within the current directory
240+ /// that match any of the specified glob patterns.
241+ /// </summary>
242+ /// <param name="patterns">An array of glob patterns to match against the names of files.</param>
243+ /// <param name="excludes">An optional array of glob patterns to exclude files.</param>
244+ /// <param name="cancellationToken">An optional cancellation token to cancel the operation.</param>
245+ /// <returns>
246+ /// An async-enumerable collection of <see cref="VirtualFile"/> instances.
247+ /// </returns>
248+ protected virtual IAsyncEnumerable < VirtualFile > GetFilesCoreAsync ( string [ ] patterns , string [ ] ? excludes , CancellationToken cancellationToken )
249+ {
250+ return new FileTreeAsyncEnumerable < VirtualNode , VirtualFile > ( this , cancellationToken )
251+ {
252+ Patterns = patterns ,
253+ Excludes = excludes ?? [ ] ,
254+ FileNameSelector = node => node . Name ,
255+ ShouldIncludePredicate = node => node is VirtualFile ,
256+ ShouldRecursePredicate = node => node is VirtualDirectory ,
257+ ChildrenSelector = ( node , token ) => ( ( VirtualDirectory ) node ) . GetFileNodesCoreAsync ( token ) ,
258+ ResultSelector = node => ( VirtualFile ) node
259+ } ;
260+ }
261+
262+ /// <summary>
263+ /// Core implementation for asynchronously returning an async-enumerable collection of directories within the current directory
264+ /// that match any of the specified glob patterns.
265+ /// </summary>
266+ /// <param name="patterns">An array of glob patterns to match against the names of directories.</param>
267+ /// <param name="excludes">An optional array of glob patterns to exclude directories.</param>
268+ /// <param name="cancellationToken">An optional cancellation token to cancel the operation.</param>
269+ /// <returns>
270+ /// An async-enumerable collection of <see cref="VirtualDirectory"/> instances.
271+ /// </returns>
272+ protected virtual IAsyncEnumerable < VirtualDirectory > GetDirectoriesCoreAsync ( string [ ] patterns , string [ ] ? excludes , CancellationToken cancellationToken )
273+ {
274+ return new FileTreeAsyncEnumerable < VirtualNode , VirtualDirectory > ( this , cancellationToken )
275+ {
276+ Patterns = patterns ,
277+ Excludes = excludes ?? [ ] ,
278+ FileNameSelector = node => node . Name ,
279+ ShouldIncludePredicate = node => node is VirtualDirectory ,
280+ ShouldRecursePredicate = node => node is VirtualDirectory ,
281+ ChildrenSelector = ( node , token ) => ( ( VirtualDirectory ) node ) . GetFileNodesCoreAsync ( token ) ,
282+ ResultSelector = node => ( VirtualDirectory ) node
283+ } ;
284+ }
246285}
0 commit comments