MultiSwitch 1.0.0

A fluent api that will help you to match patterns of primitives.
So basically a switch statement with multiple variables.

There is a newer version of this package available.
See the version list below for details.
Install-Package MultiSwitch -Version 1.0.0
dotnet add package MultiSwitch --version 1.0.0
<PackageReference Include="MultiSwitch" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MultiSwitch --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

MultiSwitch

A fluent api that will help you to match patterns of primitives.
So basically a switch statement with multiple variables.

Inspired by @anton-gogolev at https://stackoverflow.com/a/7967689/605129

Basic usage example

public void ShouldFindOneMatch()
{
    var correctMatchWasExecuted = false;
    const int i = 1;
    const int j = 34;
    const bool k = true;
    MultiSwitch.Match(i, j, k).
        With(1, 2, false).Do(() => Console.WriteLine("1, 2, 3")).
        With(1, 34, false).Do(() => Console.WriteLine("1, 34, false")).
        With(1, 34, true).Do(() =>
        {
            Console.WriteLine("1, 34, true");
            correctMatchWasExecuted = true;
        });

    Assert.That(correctMatchWasExecuted);

}

Usage with default action

public void ShouldExecuteDefault()
{
    var defaultWasExecuted = false;

    const int i = 1;
    const int j = 34;
    const bool k = true;
    MultiSwitch.Match(i, j, k).
        With(1, 2, false).Do(() => Console.WriteLine("1, 2, 3")).
        With(1, 34, false).Do(() => Console.WriteLine("1, 34, false")).
        Default(() =>
        {
            Console.WriteLine("This is default action if not match found");
            defaultWasExecuted = true;
        });

    Assert.That(defaultWasExecuted);
}

MultiSwitch

A fluent api that will help you to match patterns of primitives.
So basically a switch statement with multiple variables.

Inspired by @anton-gogolev at https://stackoverflow.com/a/7967689/605129

Basic usage example

public void ShouldFindOneMatch()
{
    var correctMatchWasExecuted = false;
    const int i = 1;
    const int j = 34;
    const bool k = true;
    MultiSwitch.Match(i, j, k).
        With(1, 2, false).Do(() => Console.WriteLine("1, 2, 3")).
        With(1, 34, false).Do(() => Console.WriteLine("1, 34, false")).
        With(1, 34, true).Do(() =>
        {
            Console.WriteLine("1, 34, true");
            correctMatchWasExecuted = true;
        });

    Assert.That(correctMatchWasExecuted);

}

Usage with default action

public void ShouldExecuteDefault()
{
    var defaultWasExecuted = false;

    const int i = 1;
    const int j = 34;
    const bool k = true;
    MultiSwitch.Match(i, j, k).
        With(1, 2, false).Do(() => Console.WriteLine("1, 2, 3")).
        With(1, 34, false).Do(() => Console.WriteLine("1, 34, false")).
        Default(() =>
        {
            Console.WriteLine("This is default action if not match found");
            defaultWasExecuted = true;
        });

    Assert.That(defaultWasExecuted);
}

Release Notes

Initial publish

Dependencies

This package has no dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.2 275 10/23/2017
1.0.1 236 10/10/2017
1.0.0 248 10/10/2017