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

StringMatcher

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

value string

The value to match. Cannot be null.

comparison StringComparison

The string comparison rules.

Returns

StringMatcher

A new matcher.

Exceptions

ArgumentNullException

value is null.

FromRegex(string, RegexOptions)

Creates a matcher from a .NET regular expression.

public static StringMatcher FromRegex(string pattern, RegexOptions options = RegexOptions.None)

Parameters

pattern string

The regular expression pattern. Cannot be null.

options RegexOptions

Regular expression options.

Returns

StringMatcher

A new matcher.

Remarks

Matching uses a two-second timeout. Add ^ and $ to require a full-string match.

Exceptions

ArgumentNullException

pattern is null.

ArgumentException

pattern is 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

value string

The value to compare or match.

Returns

bool

true if every configured constraint is satisfied; otherwise false.

Parse(string)

Creates an exact matcher or wildcard matcher depending on whether the pattern contains * or ?.

public static StringMatcher Parse(string pattern)

Parameters

pattern string

The 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

predicate Func<string, bool>

The predicate to invoke for each candidate.

description string

A 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

pattern string

The wildcard pattern. Cannot be null.

ignoreCase bool

true to ignore character casing.

Returns

StringMatcher

A new matcher.

Exceptions

ArgumentNullException

pattern is null.

Operators

implicit operator StringMatcher(string)

Converts a string into a StringMatcher using Parse(string).

public static implicit operator StringMatcher(string pattern)

Parameters

pattern string

The exact string or wildcard pattern.

Returns

StringMatcher

The matcher created from the supplied string.