PatternCollection Class

Namespace
Kampute.DocToolkit.Collections
Assembly
  • Kampute.DocToolkit.dll

Definition

Represents a collection of patterns that can be used to match string values using exact matches and wildcard patterns.
public class PatternCollection : IReadOnlyPatternCollection, ICollection<string>
Inheritance
Implements

Remarks

The PatternCollection class maintains three types of patterns:
  • Exact matchesPatterns that must match exactly (e.g., "System.Text")
  • Wildcard patternsPatterns ending with a separator followed by a wildcard character (e.g., "System.*")
  • Universal matchThe single wildcard character "*" that matches all non-empty values
The matching is case-sensitive and follows these rules:
  • For exact patterns, the value must match exactly
  • For wildcard patterns, the value must start with the pattern before the wildcard and be followed by either nothing or the separator character
  • The universal match pattern "*" matches any non-null and non-empty value
When searching for matching patterns, exact matches take precedence over wildcard patterns, and longer wildcard patterns take precedence over shorter ones.

Thread Safety

Public static members of the type are guaranteed to be thread-safe. However, public instance members are not thread-safe.

Constructors

PatternCollection(char)Initializes a new instance of the PatternCollection class with the specified separator character.

Fields

WildcardThe wildcard character used in patterns.

Properties

CountGets the number of patterns in the collection.
MatchesAllGets a value indicating whether the collection matches all non-empty values.
SeparatorGets the character used to separate segments in patterns.

Methods

Add(string)Adds a pattern to the collection if it does not already exist.
Clear()Clears all patterns from the collection.
Contains(string)Determines whether the collection contains the specified pattern.
GetEnumerator()Returns an enumerator that iterates through the patterns in the collection.
IsUniversalMatch(ReadOnlySpan<char>)Determines whether the specified pattern is a universal match pattern.
Matches(string)Determines whether the specified value matches any pattern in the collection.
Remove(string)Removes the specified pattern from the collection.
TryGetMatchingPattern(string, out string)Attempts to retrieve a pattern that matches the specified value.

Explicit Interface Implementations

ICollection<string>.IsReadOnlyGets a value indicating whether the collection is read-only.
ICollection<string>.Add(string)Adds a pattern to the collection.
ICollection<string>.CopyTo(string[], int)Copies the patterns in the collection to the specified array starting at the specified index.
IEnumerable.GetEnumerator()Returns an enumerator that iterates through the patterns in the collection.