Class StateMachine<TStateEnum>
Lockfree enum-based state machine. Transitions are O(1).
Inherited Members
Namespace: Microsoft.Graph.Communications.Common
Assembly: Microsoft.Graph.Communications.Common.dll
Syntax
public sealed class StateMachine<TStateEnum>
where TStateEnum : struct, IComparable, IFormattable, IConvertible
Type Parameters
| Name | Description |
|---|---|
| TStateEnum | The enum type which represents state. |
Constructors
StateMachine(TStateEnum, StateMachine<TStateEnum>.Transition[])
Initializes a new instance of the StateMachine<TStateEnum> class.
Declaration
public StateMachine(TStateEnum initalState, StateMachine<TStateEnum>.Transition[] transitions)
Parameters
| Type | Name | Description |
|---|---|---|
| TStateEnum | initalState | State of the inital. |
| StateMachine.Transition<>[] | transitions | The transitions. |
Properties
State
Gets the state.
Declaration
public TStateEnum State { get; }
Property Value
| Type | Description |
|---|---|
| TStateEnum | The state. |
Methods
ToString()
Returns a String that represents this instance.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| String | A String that represents this instance. |
Overrides
TransitionState(TStateEnum)
Transition to next state. Transition to same state is not allowed. Non valid transition throws exception.
Declaration
public TStateEnum TransitionState(TStateEnum newState)
Parameters
| Type | Name | Description |
|---|---|---|
| TStateEnum | newState | The new state. |
Returns
| Type | Description |
|---|---|
| TStateEnum | Previous state |
Exceptions
| Type | Condition |
|---|---|
| Exception | If transition is not allow, exception is thrown. |
TransitionStateSafe(TStateEnum)
Transition to the next state. Transition to same state has to be allowed via transitions. Non valid transition returns null.
Declaration
public TStateEnum? TransitionStateSafe(TStateEnum newState)
Parameters
| Type | Name | Description |
|---|---|---|
| TStateEnum | newState | The new state. |
Returns
| Type | Description |
|---|---|
| Nullable<TStateEnum> | Previous state or |