次の方法で共有


IPatternMatcherFactory2.CreatePatternMatcher Method

Definition

Gets an IPatternMatcher given a search pattern and search options.

public:
 Microsoft::VisualStudio::Text::PatternMatching::IPatternMatcher ^ CreatePatternMatcher(System::String ^ pattern, Microsoft::VisualStudio::Text::PatternMatching::PatternMatcherCreationOptions ^ creationOptions, Microsoft::VisualStudio::Text::PatternMatching::IPatternMatcher ^ linkedMatcher);
public Microsoft.VisualStudio.Text.PatternMatching.IPatternMatcher CreatePatternMatcher (string pattern, Microsoft.VisualStudio.Text.PatternMatching.PatternMatcherCreationOptions creationOptions, Microsoft.VisualStudio.Text.PatternMatching.IPatternMatcher linkedMatcher);
abstract member CreatePatternMatcher : string * Microsoft.VisualStudio.Text.PatternMatching.PatternMatcherCreationOptions * Microsoft.VisualStudio.Text.PatternMatching.IPatternMatcher -> Microsoft.VisualStudio.Text.PatternMatching.IPatternMatcher
Public Function CreatePatternMatcher (pattern As String, creationOptions As PatternMatcherCreationOptions, linkedMatcher As IPatternMatcher) As IPatternMatcher

Parameters

pattern
String

Describes the search pattern that candidate strings will be compared against for relevancy.

creationOptions
PatternMatcherCreationOptions

Defines parameters for what should be considered relevant in a match.

linkedMatcher
IPatternMatcher

A matcher whose cache should be shared with the created matcher.

Returns

Remarks

As opposed to CreatePatternMatcher(String, PatternMatcherCreationOptions), this overload creates a IPatternMatcher with a shared cache. Use this overload in contexts with frequently changing patterns to reduce allocations and throw-away work. Note that sharing the cache between IPatternMatchers used from multiple threads may lead to lock contention. It's recommended to profile prior to opting in.

This pattern matcher uses the concepts of a 'Pattern' and a 'Candidate' to to differentiate between what the user types to search and what the system compares against. The pattern and some PatternMatcherCreationOptions are specified in here in order to obtain an IPatternMatcher.

The user can then call TryMatch(String) repeatedly with multiple candidates to filter out non-matches, and obtain sortable PatternMatch objects to help decide what the user actually wanted.

A few examples are useful here. Suppose the user obtains an IPatternMatcher using the following: Pattern = "PatMat"

The following calls to TryMatch could expect these results: Candidate = "PatternMatcher" Returns a match containing CamelCaseExact.

Candidate = "IPatternMatcher" Returns a match containing CamelCaseSubstring

Candidate = "patmat" Returns a match containing Exact, but IsCaseSensitive will be false.

Candidate = "Not A Match" Returns null.

To determine sort order, call CompareTo(PatternMatch).

Applies to