GlobCollection Class
Represents a collection of glob patterns that can be evaluated together.
public sealed class GlobCollection : IGlobEvaluatable, IEnumerable<IGlobEvaluatable>, IReadOnlyCollection<IGlobEvaluatable>, IReadOnlyList<IGlobEvaluatable>, IEnumerableExample
Combine multiple glob patterns with include and exclude rules:
var globs = new GlobCollection(
Glob.Parse("**/*.txt", GlobDialect.Standard),
Glob.Parse("!temp/**/*", GlobDialect.Standard));
foreach (var file in globs.EnumerateFiles("C:/MyProject"))
{
Console.WriteLine(file);
}- Implements
Constructors
| Name | Description |
|---|---|
| GlobCollection(IGlobEvaluatable[]) | Initializes a new instance of the GlobCollection class. |
GlobCollection(IGlobEvaluatable[])
GlobCollection.csInitializes a new instance of the GlobCollection class.
public GlobCollection(params IGlobEvaluatable[] globs)Parameters
globsIGlobEvaluatable[]- The glob patterns to include in the collection. The collection keeps a copy of the array.
Exceptions
ArgumentNullExceptionglobsisnull.ArgumentExceptionglobscontains anullelement.
Properties
| Name | Description |
|---|---|
| Count | Gets the number of glob patterns in the collection. |
| Meziantou.Framework.Globbing.IGlobEvaluatable.CanMatchDirectories | |
| Meziantou.Framework.Globbing.IGlobEvaluatable.CanMatchFiles | |
| Meziantou.Framework.Globbing.IGlobEvaluatable.Mode | |
| Meziantou.Framework.Globbing.IGlobEvaluatable.TraverseDirectories |
Count
GlobCollection.csMeziantou.Framework.Globbing.IGlobEvaluatable.CanMatchDirectories
GlobCollection.csMeziantou.Framework.Globbing.IGlobEvaluatable.CanMatchFiles
GlobCollection.csMeziantou.Framework.Globbing.IGlobEvaluatable.Mode
GlobCollection.csMeziantou.Framework.Globbing.IGlobEvaluatable.TraverseDirectories
GlobCollection.csIndexers
| Name | Description |
|---|---|
| this[int] | Gets the glob pattern at the specified index. |
this[int]
GlobCollection.csGets the glob pattern at the specified index.
public IGlobEvaluatable this[int index] { get; }Methods
| Name | Description |
|---|---|
| Create(ReadOnlySpan<IGlobEvaluatable>) | |
| GetEnumerator() | |
| IsMatch(ReadOnlySpan<char>, ReadOnlySpan<char>, PathItemType?) | Determines whether the specified path matches any pattern in the collection. |
| IsPartialMatch(ReadOnlySpan<char>, ReadOnlySpan<char>) | Determines whether a directory should be recursed into when enumerating files. |
| LoadGitIgnoreAsync(Stream, CancellationToken) | Loads a gitignore stream asynchronously and creates a GlobCollection from it. |
| LoadGitIgnoreAsync(TextReader, CancellationToken) | Loads a gitignore reader asynchronously and creates a GlobCollection from it. |
| LoadGitIgnoreAsync(string, string?, CancellationToken) | Loads a gitignore file located in a subdirectory asynchronously and creates a GlobCollection from it. |
| LoadGitIgnoreAsync(string, CancellationToken) | Loads a gitignore file asynchronously and creates a GlobCollection from it. |
| ParseGitIgnore(ReadOnlySpan<char>) | Loads gitignore content and creates a GlobCollection from it. |
| ParseGitIgnore(ReadOnlySpan<char>, string?) | Loads the content of a gitignore file located in a subdirectory and creates a GlobCollection from it. |
| System.Collections.IEnumerable.GetEnumerator() |
Create(ReadOnlySpan<IGlobEvaluatable>)
GlobCollection.cspublic static GlobCollection Create(ReadOnlySpan<IGlobEvaluatable> globs)No documentation is available.
GetEnumerator()
GlobCollection.cspublic IEnumerator<IGlobEvaluatable> GetEnumerator()No documentation is available.
IsMatch(ReadOnlySpan<char>, ReadOnlySpan<char>, PathItemType?)
GlobCollection.csDetermines whether the specified path matches any pattern in the collection.
public bool IsMatch(ReadOnlySpan<char> directory, ReadOnlySpan<char> filename, PathItemType? itemType)Parameters
directoryReadOnlySpan<char>- The directory part of the path to match.
filenameReadOnlySpan<char>- The filename part of the path to match.
itemTypePathItemType?- The type of the path item (file or directory), or
nullif unknown.
Returns
bool true if the path matches any include pattern and no exclude pattern; otherwise, false. A collection created from gitignore content resolves the path against the last pattern that matches it instead, as git does, and reports a path as matched when one of its ancestor directories is: git cannot re-include a path whose parent directory is excluded.
IsPartialMatch(ReadOnlySpan<char>, ReadOnlySpan<char>)
GlobCollection.csDetermines whether a directory should be recursed into when enumerating files.
public bool IsPartialMatch(ReadOnlySpan<char> folderPath, ReadOnlySpan<char> filename)Parameters
folderPathReadOnlySpan<char>- The folder path to check.
filenameReadOnlySpan<char>- The filename part of the path to check.
Returns
bool true if the directory could contain matches; otherwise, false. A directory whose whole content is excluded by an exclude pattern, such as !**/node_modules/**, cannot contain matches. For a collection created from gitignore content, a directory can contain matches when it is excluded, or when a pattern can exclude a path below it.
LoadGitIgnoreAsync overloads
LoadGitIgnoreAsync(Stream, CancellationToken)
GlobCollection.csLoads a gitignore stream asynchronously and creates a GlobCollection from it.
net10.0
public static Task<GlobCollection> LoadGitIgnoreAsync(Stream stream, CancellationToken cancellationToken = default)net11.0
public static Task<GlobCollection> LoadGitIgnoreAsync(Stream stream, CancellationToken cancellationToken = default)Parameters
streamStream- The stream containing the gitignore content.
cancellationTokenCancellationToken- The cancellation token.
Returns
Remarks
The content is decoded as UTF-8, unless it starts with the byte order mark of another encoding (UTF-16 or UTF-32). As git does, only that first byte order mark is skipped.
LoadGitIgnoreAsync(TextReader, CancellationToken)
GlobCollection.csLoads a gitignore reader asynchronously and creates a GlobCollection from it.
net10.0
public static Task<GlobCollection> LoadGitIgnoreAsync(TextReader reader, CancellationToken cancellationToken = default)net11.0
public static Task<GlobCollection> LoadGitIgnoreAsync(TextReader reader, CancellationToken cancellationToken = default)Parameters
readerTextReader- The reader providing the gitignore content.
cancellationTokenCancellationToken- The cancellation token.
Returns
LoadGitIgnoreAsync(string, string?, CancellationToken)
GlobCollection.csLoads a gitignore file located in a subdirectory asynchronously and creates a GlobCollection from it.
net10.0
public static Task<GlobCollection> LoadGitIgnoreAsync(string path, string? baseDirectory, CancellationToken cancellationToken = default)net11.0
public static Task<GlobCollection> LoadGitIgnoreAsync(string path, string? baseDirectory, CancellationToken cancellationToken = default)Parameters
pathstring- The path to the gitignore file.
baseDirectorystring?- The directory that holds the gitignore file, relative to the root of the paths given to the collection, such as
src/App.null, an empty string or.stand for the root. cancellationTokenCancellationToken- The cancellation token.
Returns
Remarks
The file is decoded as GlobCollection.LoadGitIgnoreAsync decodes a stream. The rules apply as described in GlobCollection.ParseGitIgnore.
LoadGitIgnoreAsync(string, CancellationToken)
GlobCollection.csLoads a gitignore file asynchronously and creates a GlobCollection from it.
public static Task<GlobCollection> LoadGitIgnoreAsync(string path, CancellationToken cancellationToken = default)Parameters
pathstring- The path to the gitignore file.
cancellationTokenCancellationToken- The cancellation token.
Returns
Remarks
The file is decoded as GlobCollection.LoadGitIgnoreAsync decodes a stream.
ParseGitIgnore overloads
ParseGitIgnore(ReadOnlySpan<char>)
GlobCollection.csLoads gitignore content and creates a GlobCollection from it.
public static GlobCollection ParseGitIgnore(ReadOnlySpan<char> gitIgnoreContent)Parameters
gitIgnoreContentReadOnlySpan<char>- The gitignore content.
Returns
Remarks
As git does, an entry that no path can match, such as one holding an unterminated bracket expression or ending with an escape character, is ignored instead of making the whole content invalid.
ParseGitIgnore(ReadOnlySpan<char>, string?)
GlobCollection.csLoads the content of a gitignore file located in a subdirectory and creates a GlobCollection from it.
public static GlobCollection ParseGitIgnore(ReadOnlySpan<char> gitIgnoreContent, string? baseDirectory)Parameters
gitIgnoreContentReadOnlySpan<char>- The gitignore content.
baseDirectorystring?- The directory that holds the gitignore file, relative to the root of the paths given to the collection, such as
src/App.null, an empty string or.stand for the root.
Returns
Remarks
The rules only apply to the paths below baseDirectory, and they are matched relative to it, as git does for the .gitignore file of a subdirectory. The collection does not match the other paths, nor baseDirectory itself.