8000 Add FileSystemEnumerable usage example by carlossanlop · Pull Request #5245 · dotnet/dotnet-api-docs · GitHub
[go: up one dir, main page]

Skip to content

Add FileSystemEnumerable usage example #5245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.IO;
using System.IO.Enumeration;

namespace MyNamespace
{
public class MyClassCS
{
static void Main()
{
var enumeration = new FileSystemEnumerable<string>(
directory: Path.GetTempPath(), // search Temp directory
transform: (ref FileSystemEntry entry) => entry.ToFullPath(), // map FileSystemEntry to string (see FileSystemEnumerable generic argument)
options: new EnumerationOptions()
{
RecurseSubdirectories = true
})
{
// The following predicate will be used to filter the file entries
ShouldIncludePredicate = (ref FileSystemEntry entry) => !entry.IsDirectory && Path.GetExtension(entry.ToFullPath()) == ".tmp"
};

// Prints all ".tmp" files from Temp directory
foreach (string filePath in enumeration)
{
Console.WriteLine(filePath);
}
}
}

}
12 changes: 11 additions & 1 deletion xml/System.IO.Enumeration/FileSystemEnumerable`1.xml
4F8B
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,17 @@
<Docs>
<typeparam name="TResult">The type that this enumerable encapsulates.</typeparam>
<summary>Allows utilizing custom filter predicates and transform delegates for enumeration purposes.</summary>
<remarks>To be added.</remarks>
<remarks>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to put the example in the remarks of the type, because I think it's the most visible place.

<format type="text/markdown"><![CDATA[

## Examples

The following example shows how to use the <xref:System.IO.Enumeration.FileSystemEnumerable`1> constructor with basic filtering options:

[!code-csharp[FileSystemEnumerable](~/samples/snippets/csharp/VS_Snippets_CLR/IO.Enumeration.FileSystemEnumerable/CS/Sample1.cs)]

]]></format>
</remarks>
</Docs>
<Members>
<Member MemberName=".ctor">
Expand Down
0