TextFilterPattern Class
Definition
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
patternstringThe pattern text. Must not be null.
actionTextFilterActionThe action taken when the pattern matches a value.
kindTextFilterPatternKindThe syntax used to interpret
pattern.ignoreCasebool?An optional case-sensitivity override for this pattern; null inherits the IgnoreCase setting of the filter the pattern is compiled into.
Exceptions
- ArgumentNullException
patternis null.- ArgumentException
patternis empty or consists solely of white space.- ArgumentOutOfRangeException
patternis longer than Bodu.Text.Filtering.TextFilterPattern.MaxPatternLength characters, oractionorkindis not a defined enumeration value.
Properties
Action
Gets the action taken when the pattern matches a value.
public TextFilterAction Action { get; }
Property Value
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
Pattern
Gets the pattern text as originally supplied.
public string Pattern { get; }
Property Value
Methods
Exclude(string, TextFilterPatternKind, bool?)
Creates an exclude pattern.
public static TextFilterPattern Exclude(string pattern, TextFilterPatternKind kind = TextFilterPatternKind.Wildcard, bool? ignoreCase = null)
Parameters
patternstringThe pattern text. Must not be null.
kindTextFilterPatternKindThe syntax used to interpret
pattern.ignoreCasebool?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
patternis null.- ArgumentException
patternis empty or consists solely of white space.- ArgumentOutOfRangeException
patternis longer than Bodu.Text.Filtering.TextFilterPattern.MaxPatternLength characters, orkindis 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
patternstringThe pattern text. Must not be null.
kindTextFilterPatternKindThe syntax used to interpret
pattern.ignoreCasebool?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
patternis null.- ArgumentException
patternis empty or consists solely of white space.- ArgumentOutOfRangeException
patternis longer than Bodu.Text.Filtering.TextFilterPattern.MaxPatternLength characters, orkindis 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
| Product | Versions |
|---|---|
| .NET | 8, 10 |