Table of Contents

TextFilterBuilder Class

Definition

Namespace
Bodu.Text.Filtering
Assembly
Bodu.Text.Filtering.dll
Package
Bodu.Text.Filtering 1.0.0
Source
TextFilterBuilder.cs

Provides a fluent builder for assembling the patterns of a TextFilter, in the style of Microsoft.Extensions.FileSystemGlobbing's Matcher.

public sealed class TextFilterBuilder
Inheritance
TextFilterBuilder
Inherited Members
Extension Methods

Examples

var filter = new TextFilterBuilder()
    .AddInclude("error*")
    .AddInclude("{warn,fatal}*")
    .AddExclude("*debug*")
    .Build();

Remarks

Patterns accumulate in the order they are added - the order that becomes significant under LastMatchWins. The builder itself performs only per-pattern validation; grammar and regular-expression compilation errors surface from Build().

Constructors

TextFilterBuilder()

Initializes a new instance of the TextFilterBuilder class with default options.

public TextFilterBuilder()

TextFilterBuilder(TextFilterOptions)

Initializes a new instance of the TextFilterBuilder class with the specified options.

public TextFilterBuilder(TextFilterOptions options)

Parameters

options TextFilterOptions

The options the built filter compiles with. Must not be null.

Exceptions

ArgumentNullException

options is null.

Methods

Add(TextFilterPattern)

Adds an already constructed pattern.

public TextFilterBuilder Add(TextFilterPattern pattern)

Parameters

pattern TextFilterPattern

The pattern to add. Must not be null.

Returns

TextFilterBuilder

This builder, for chaining.

Exceptions

ArgumentNullException

pattern is null.

AddExclude(string)

Adds a wildcard exclude pattern.

public TextFilterBuilder AddExclude(string globPattern)

Parameters

globPattern string

The wildcard pattern text. Must not be null.

Returns

TextFilterBuilder

This builder, for chaining.

Exceptions

ArgumentNullException

globPattern is null.

ArgumentException

globPattern is empty or consists solely of white space.

ArgumentOutOfRangeException

globPattern exceeds the maximum pattern length.

AddExcludeRegex(string)

Adds a regular-expression exclude pattern.

public TextFilterBuilder AddExcludeRegex(string regexPattern)

Parameters

regexPattern string

The regular-expression text. Must not be null.

Returns

TextFilterBuilder

This builder, for chaining.

Exceptions

ArgumentNullException

regexPattern is null.

ArgumentException

regexPattern is empty or consists solely of white space.

ArgumentOutOfRangeException

regexPattern exceeds the maximum pattern length.

AddInclude(string)

Adds a wildcard include pattern.

public TextFilterBuilder AddInclude(string globPattern)

Parameters

globPattern string

The wildcard pattern text. Must not be null.

Returns

TextFilterBuilder

This builder, for chaining.

Exceptions

ArgumentNullException

globPattern is null.

ArgumentException

globPattern is empty or consists solely of white space.

ArgumentOutOfRangeException

globPattern exceeds the maximum pattern length.

AddIncludeRegex(string)

Adds a regular-expression include pattern.

public TextFilterBuilder AddIncludeRegex(string regexPattern)

Parameters

regexPattern string

The regular-expression text. Must not be null.

Returns

TextFilterBuilder

This builder, for chaining.

Exceptions

ArgumentNullException

regexPattern is null.

ArgumentException

regexPattern is empty or consists solely of white space.

ArgumentOutOfRangeException

regexPattern exceeds the maximum pattern length.

AddParsed(IEnumerable<string>)

Parses raw lines using the gitignore conventions and adds the resulting patterns.

public TextFilterBuilder AddParsed(IEnumerable<string> lines)

Parameters

lines IEnumerable<string>

The lines to parse. Must not be null or contain null entries.

Returns

TextFilterBuilder

This builder, for chaining.

Exceptions

ArgumentNullException

lines is null.

ArgumentException

lines contains a null entry, or a line's pattern text is empty.

AddParsed(string)

Parses one raw line using the gitignore conventions and adds the resulting pattern, if any.

public TextFilterBuilder AddParsed(string line)

Parameters

line string

The line to parse. Must not be null.

Returns

TextFilterBuilder

This builder, for chaining.

Remarks

Blank lines and # comment lines are skipped; a leading ! makes the pattern an exclude; ! and # escape a literal leading character. See Parse(IEnumerable<string>).

Exceptions

ArgumentNullException

line is null.

ArgumentException

The line's pattern text is empty (for example a lone !).

Build()

Compiles the accumulated patterns into a TextFilter.

public TextFilter Build()

Returns

TextFilter

The compiled filter.

Remarks

The builder can keep accumulating patterns after a build; later builds include them.

Exceptions

ArgumentException

A wildcard pattern is malformed or a regular-expression pattern is not valid.

Applies to

ProductVersions
.NET8, 10