StateCore 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package StateCore --version 0.1.0
                    
NuGet\Install-Package StateCore -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="StateCore" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="StateCore" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="StateCore" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add StateCore --version 0.1.0
                    
#r "nuget: StateCore, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package StateCore@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=StateCore&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=StateCore&version=0.1.0
                    
Install as a Cake Tool

StateCore

The library provides a flexible framework for creating finite state machines in C#.

Features

  • Define states and triggers.
  • Create state machines with customizable transitions.
  • Easily integrate into your projects for handling state-driven logic.

Basic Usage

To get started with the FiniteStateMachine library, you need to define your states and triggers as enums:

public enum State
{
    Paused,
    Playing,
    Stopped
}

public enum Trigger
{
    Play,
    Pause,
    Stop
}

Building a State Machine

 var statemachine = StateMachine<EnumState, Trigger>
            .WithInitialState(EnumState.Paused)
            .State(EnumState.Paused, cfg => cfg
                .On(Trigger.Play).GoTo(EnumState.Playing)
                .On(Trigger.Pause).GoTo(EnumState.Paused)
                .On(Trigger.Stop).GoTo(EnumState.Stopped)
            )
            .State(EnumState.Stopped, cfg => cfg
                .On(Trigger.Play).GoTo(EnumState.Playing)
                .On(Trigger.Pause).GoTo(EnumState.Stopped)
                .On(Trigger.Stop).GoTo(EnumState.Stopped)  
            )
            .State(EnumState.Playing, cfg => cfg
                .On(Trigger.Play).GoTo(EnumState.Playing)
                .On(Trigger.Pause).GoTo(EnumState.Paused)
                .On(Trigger.Stop).GoTo(EnumState.Stopped)  
            )
            .Build();

Once the state machine is built, you can trigger transitions based on current state:

var result = stateMachine.Trigger(Trigger.Play);
Console.WriteLine(stateMachine.CurrentState); // Outputs: Playing
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.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
0.2.0 140 11/6/2025
0.1.0 144 11/5/2025