FluentMatch 1.0.0
dotnet add package FluentMatch --version 1.0.0
NuGet\Install-Package FluentMatch -Version 1.0.0
<PackageReference Include="FluentMatch" Version="1.0.0" />
paket add FluentMatch --version 1.0.0
#r "nuget: FluentMatch, 1.0.0"
// Install FluentMatch as a Cake Addin #addin nuget:?package=FluentMatch&version=1.0.0 // Install FluentMatch as a Cake Tool #tool nuget:?package=FluentMatch&version=1.0.0
Getting Started
FluentMatch represents a string matching rule with the StringMatcher
class. To create a StringMatcher
, use one of the static methods available on the StringMatch
class:
StringMatcher dogMatcher = StringMatch.Equals("dog");
The StringMatcher
can then be used to test strings with the Matches
method:
bool dogMatches = dogMatcher.Matches("dog"); // returns true
bool catMatches = dogMatcher.Matches("cat"); // returns false
StringMatcher
can also operate on collections of strings:
string[] pets = new[] { "dog", "cat", "bird" };
bool hasDog = dogMatcher.MatchesAny(pets); // returns true
bool onlyDogs = dogMatcher.MatchesAll(pets); // returns false
FluentMatch includes a variety of string matching rules and options:
StringMatch.Contains("dog", StringComparison.Ordinal);
StringMatch.IsNotNullOrEmpty();
StringMatch.Regex(@"^[A-Z]{3} \d{3}$");
Complex Scenarios
FluentMatch provides options for combining multiple string matchers to create complex rules:
// Match any string containing either "dog" or "cat"
StringMatch.Contains("dog").Or(StringMatch.Contains("cat"));
// Match strings with specified start and end
StringMatch.StartsWith("a").And(StringMatch.EndsWith("z"));
StringMatcher
can also be configured to apply a transformation to input strings before testing:
StringMatcher matcher = StringMatch.Equals("abc").WithTransform(n => n.Trim());
bool result = matcher.Matches(" abc "); // returns true
Custom Matching Logic
If the built-in matching rules do not cover your use case, you can create a StringMatcher
based on a delegate:
StringMatcher threeCharacters = StringMatch.Where(n => n.Length == 3);
You can also define matching logic by creating a custom StringMatcher
class.
class ProductKeyMatcher : StringMatcher
{
public override bool Matches(string input)
{
return input.StartsWith("PN-") && input.Skip(3).All(n => char.IsDigit(n));
}
}
/* snip */
StringMatcher productKeyMatcher = new ProductKeyMatcher();
bool valid = productKeyMatcher.Matches("PN-1234");
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 575 | 5/30/2020 |