Skip to content
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

Advanced filter in FromDirectory #166

Merged
merged 7 commits into from Mar 13, 2021

Conversation

Kaplas80
Copy link
Contributor

Description

This PR allows using a Func to define the filter in NodeFactory.FromDirectory methods.

This way, the users can define more precisely the files to add to the container.

On the other side, this method will be slower than wildcard filters because it first enumerates all files and, later, filters them.

Example

Get files using a regular expression:

Node node = NodeFactory.FromDirectory(tempDir, x => Regex.IsMatch(x, @"file\d\.(txt|bin)$"));

@Kaplas80 Kaplas80 marked this pull request as ready for review February 25, 2021 18:20
@pleonex pleonex self-requested a review March 13, 2021 13:15
@pleonex pleonex added this to the vNext milestone Mar 13, 2021
Copy link
Member

@pleonex pleonex left a comment

Choose a reason for hiding this comment

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

Thanks! It looks like a very useful feature!
Just a few comments about style and safety.

src/Yarhl/FileSystem/NodeFactory.cs Show resolved Hide resolved
if (string.IsNullOrEmpty(dirPath))
throw new ArgumentNullException(nameof(dirPath));

if (dirPath[dirPath.Length - 1] == Path.DirectorySeparatorChar)
Copy link
Member

Choose a reason for hiding this comment

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

The one-line conditions not related to guards should have braces to prevent future bugs (the previous function doesn't follow this rule this rule but I think it's old code before this rule was introduced).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

src/Yarhl/FileSystem/NodeFactory.cs Show resolved Hide resolved
Copy link
Member

@pleonex pleonex left a comment

Choose a reason for hiding this comment

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

All good. Thanks!

@pleonex pleonex merged commit 1849bed into SceneGate:develop Mar 13, 2021
@Kaplas80 Kaplas80 deleted the feature/filter-files branch March 13, 2021 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants