Class StringMatcher
- Namespace
- AsmLocator
- Assembly
- AsmLocator.dll
Represents a reusable string-matching strategy. Implicit conversion from string uses exact matching
unless the value contains * or ?, in which case wildcard matching is used.
Use FromRegex(string, RegexOptions) or Where(Func<string, bool>, string) for regular expressions or custom predicates.
public sealed class StringMatcher
- Inheritance
-
StringMatcher
- Inherited Members
Properties
Any
Gets a matcher that accepts every input string.
public static StringMatcher Any { get; }
Property Value
Methods
Exact(string, StringComparison)
Creates a matcher that compares the complete input with value.
public static StringMatcher Exact(string value, StringComparison comparison = StringComparison.Ordinal)
Parameters
valuestringThe value to match. Cannot be null.
comparisonStringComparisonThe string comparison rules.
Returns
- StringMatcher
A new matcher.
Exceptions
- ArgumentNullException
valueis null.
FromRegex(string, RegexOptions)
Creates a matcher from a .NET regular expression.
public static StringMatcher FromRegex(string pattern, RegexOptions options = RegexOptions.None)
Parameters
patternstringThe regular expression pattern. Cannot be null.
optionsRegexOptionsRegular expression options.
Returns
- StringMatcher
A new matcher.
Remarks
Matching uses a two-second timeout. Add ^ and $ to require a full-string match.
Exceptions
- ArgumentNullException
patternis null.- ArgumentException
patternis not a valid regular expression.
IsMatch(string?)
Tests the value; a null input is treated as an empty string.
public bool IsMatch(string? value)
Parameters
valuestringThe value to compare or match.
Returns
Parse(string)
Creates an exact matcher or wildcard matcher depending on whether the pattern contains * or ?.
public static StringMatcher Parse(string pattern)
Parameters
patternstringThe pattern to parse.
Returns
- StringMatcher
A new matcher.
ToString()
Returns a readable representation of this object.
public override string ToString()
Returns
- string
A readable description.
Where(Func<string, bool>, string)
Creates a matcher backed by a custom predicate.
public static StringMatcher Where(Func<string, bool> predicate, string description = "<predicate>")
Parameters
predicateFunc<string, bool>The predicate to invoke for each candidate.
descriptionstringA display description used by ToString().
Returns
- StringMatcher
A new matcher.
Wildcard(string, bool)
Creates a wildcard matcher where * matches any number of characters and ? matches one character.
public static StringMatcher Wildcard(string pattern, bool ignoreCase = false)
Parameters
patternstringThe wildcard pattern. Cannot be null.
ignoreCasebooltrue to ignore character casing.
Returns
- StringMatcher
A new matcher.
Exceptions
- ArgumentNullException
patternis null.
Operators
implicit operator StringMatcher(string)
Converts a string into a StringMatcher using Parse(string).
public static implicit operator StringMatcher(string pattern)
Parameters
patternstringThe exact string or wildcard pattern.
Returns
- StringMatcher
The matcher created from the supplied string.