Table of Contents

TextFilterPattern Class

Definition

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

Represents one immutable filtering rule: a pattern, the action taken when it matches, the syntax the pattern is written in, and an optional case-sensitivity override.

public sealed class TextFilterPattern
Inheritance
TextFilterPattern
Inherited Members
Extension Methods

Remarks

Patterns do not match values on their own; they are compiled - together with the other patterns of a rule set - into a TextFilter via Build(IEnumerable<TextFilterPattern>). Wildcard grammar errors and regular-expression syntax errors are reported at that point, not by this constructor.

The constructor validates only shape-independent rules: the pattern text must be non-empty, must not consist solely of white space, and must not exceed Bodu.Text.Filtering.TextFilterPattern.MaxPatternLength characters (a guard against pathological patterns, mirroring the limits used elsewhere in the Bodu libraries).

Constructors

TextFilterPattern(string, TextFilterAction, TextFilterPatternKind, bool?)

Initializes a new instance of the TextFilterPattern class.

public TextFilterPattern(string pattern, TextFilterAction action, TextFilterPatternKind kind = TextFilterPatternKind.Wildcard, bool? ignoreCase = null)

Parameters

pattern string

The pattern text. Must not be null.

action TextFilterAction

The action taken when the pattern matches a value.

kind TextFilterPatternKind

The syntax used to interpret pattern.

ignoreCase bool?

An optional case-sensitivity override for this pattern; null inherits the IgnoreCase setting of the filter the pattern is compiled into.

Exceptions

ArgumentNullException

pattern is null.

ArgumentException

pattern is empty or consists solely of white space.

ArgumentOutOfRangeException

pattern is longer than Bodu.Text.Filtering.TextFilterPattern.MaxPatternLength characters, or action or kind is not a defined enumeration value.

Properties

Action

Gets the action taken when the pattern matches a value.

public TextFilterAction Action { get; }

Property Value

TextFilterAction

IgnoreCase

Gets the case-sensitivity override for this pattern.

public bool? IgnoreCase { get; }

Property Value

bool?

true to ignore case, false to match case-sensitively, or null to inherit the IgnoreCase setting of the filter the pattern is compiled into.

Kind

Gets the syntax used to interpret Pattern.

public TextFilterPatternKind Kind { get; }

Property Value

TextFilterPatternKind

Pattern

Gets the pattern text as originally supplied.

public string Pattern { get; }

Property Value

string

Methods

Exclude(string, TextFilterPatternKind, bool?)

Creates an exclude pattern.

public static TextFilterPattern Exclude(string pattern, TextFilterPatternKind kind = TextFilterPatternKind.Wildcard, bool? ignoreCase = null)

Parameters

pattern string

The pattern text. Must not be null.

kind TextFilterPatternKind

The syntax used to interpret pattern.

ignoreCase bool?

An optional case-sensitivity override for this pattern; null inherits the filter's setting.

Returns

TextFilterPattern

A new TextFilterPattern whose Action is Exclude.

Exceptions

ArgumentNullException

pattern is null.

ArgumentException

pattern is empty or consists solely of white space.

ArgumentOutOfRangeException

pattern is longer than Bodu.Text.Filtering.TextFilterPattern.MaxPatternLength characters, or kind is not a defined enumeration value.

Include(string, TextFilterPatternKind, bool?)

Creates an include pattern.

public static TextFilterPattern Include(string pattern, TextFilterPatternKind kind = TextFilterPatternKind.Wildcard, bool? ignoreCase = null)

Parameters

pattern string

The pattern text. Must not be null.

kind TextFilterPatternKind

The syntax used to interpret pattern.

ignoreCase bool?

An optional case-sensitivity override for this pattern; null inherits the filter's setting.

Returns

TextFilterPattern

A new TextFilterPattern whose Action is Include.

Exceptions

ArgumentNullException

pattern is null.

ArgumentException

pattern is empty or consists solely of white space.

ArgumentOutOfRangeException

pattern is longer than Bodu.Text.Filtering.TextFilterPattern.MaxPatternLength characters, or kind is not a defined enumeration value.

ToString()

Returns a diagnostic representation of the pattern in the form +wildcard:text or -regex:text, where the leading sign reflects Action.

public override string ToString()

Returns

string

A string describing the pattern for diagnostic display.

Applies to

ProductVersions
.NET8, 10