8000 Add FileSystemEnumerable usage example (#5245) · dotnet/dotnet-api-docs@d42a733 · GitHub
[go: up one dir, main page]

Skip to content

Commit d42a733

Browse files
carlossanlopChayoteJarochoadamsitnik
authored
Add FileSystemEnumerable usage example (#5245)
* Add FileSystemEnumerable usage example * Local methods * remove hashtags * Update samples/snippets/csharp/VS_Snippets_CLR/IO.Enumeration.FileSystemEnumerable/CS/Sample1.cs Co-authored-by: Adam Sitnik <adam.sitnik@gmail.com> * Update samples/snippets/csharp/VS_Snippets_CLR/IO.Enumeration.FileSystemEnumerable/CS/Sample1.cs Co-authored-by: ChayoteJarocho <77412126+ChayoteJarocho@users.noreply.github.com> Co-authored-by: Adam Sitnik <adam.sitnik@gmail.com>
1 parent b69eed3 commit d42a733

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.IO;
3+
using System.IO.Enumeration;
4+
5+
namespace MyNamespace
6+
{
7+
public class MyClassCS
8+
{
9+
static void Main()
10+
{
11+
var enumeration = new FileSystemEnumerable<string>(
12+
directory: Path.GetTempPath(), // search Temp directory
13+
transform: (ref FileSystemEntry entry) => entry.ToFullPath(), // map FileSystemEntry to string (see FileSystemEnumerable generic argument)
14+
options: new EnumerationOptions()
15+
{
16+
RecurseSubdirectories = true
17+
})
18+
{
19+
// The following predicate will be used to filter the file entries
20+
ShouldIncludePredicate = (ref FileSystemEntry entry) => !entry.IsDirectory && Path.GetExtension(entry.ToFullPath()) == ".tmp"
21+
};
22+
23+
// Prints all ".tmp" files from Temp directory
24+
foreach (string filePath in enumeration)
25+
{
26+
Console.WriteLine(filePath);
27+
}
28+
}
29+
}
30+
31+
}

xml/System.IO.Enumeration/FileSystemEnumerable`1.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,17 @@
3535
<Docs>
3636
<typeparam name="TResult">The type that this enumerable encapsulates.</typeparam>
3737
<summary>Allows utilizing custom filter predicates and transform delegates for enumeration purposes.</summary>
38-
<remarks>To be added.</remarks>
38+
<remarks>
39+
<format type="text/markdown"><![CDATA[
40+
41+
## Examples
42+
43+
The following example shows how to use the <xref:System.IO.Enumeration.FileSystemEnumerable`1> constructor with basic filtering options:
44+
45+
[!code-csharp[FileSystemEnumerable](~/samples/snippets/csharp/VS_Snippets_CLR/IO.Enumeration.FileSystemEnumerable/CS/Sample1.cs)]
46+
47+
]]></format>
48+
</remarks>
3949
</Docs>
4050
<Members>
4151
<Member MemberName=".ctor">

0 commit comments

Comments
 (0)
0