Skip to content

Commit ee92356

Browse files
author
Nilay Vishwakarma
committed
fix comments
1 parent 9d83dd3 commit ee92356

File tree

10 files changed

+67
-41
lines changed

10 files changed

+67
-41
lines changed

src/FsmNet/BaseStateMachine.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
/// <summary>
66
/// Base class for state machines that defines the core functionality for transitioning between states.
77
/// </summary>
8-
/// <typeparam name="TState"></typeparam>
9-
/// <typeparam name="TContext"></typeparam>
8+
/// <typeparam name="TState">State Enum Type</typeparam>
9+
/// <typeparam name="TContext">Context Type</typeparam>
1010
public abstract class BaseStateMachine<TState, TContext> : IStateMachine<TState, TContext> where TState : struct, Enum
1111
{
1212
/// <summary>
@@ -17,17 +17,17 @@ public abstract class BaseStateMachine<TState, TContext> : IStateMachine<TState,
1717
/// <summary>
1818
/// Checks if a transition to the specified target state is possible given the current context.
1919
/// </summary>
20-
/// <param name="target"></param>
21-
/// <param name="context"></param>
22-
/// <returns></returns>
20+
/// <param name="target">Target State</param>
21+
/// <param name="context">Context</param>
22+
/// <returns>If transition is possible to target state</returns>
2323
public abstract bool CanTransitionTo(TState target, TContext context);
2424

2525
/// <summary>
2626
/// Attempts to transition to the specified target state given the current context.
2727
/// </summary>
28-
/// <param name="target"></param>
29-
/// <param name="context"></param>
30-
/// <returns></returns>
28+
/// <param name="target">Target State</param>
29+
/// <param name="context">Context</param>
30+
/// <returns>If transition is successful to target state</returns>
3131
public abstract bool TryTransitionTo(TState target, TContext context);
3232
}
3333
}

src/FsmNet/EnumState.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/// <summary>
66
/// Represents a state in a finite state machine defined by an enumeration.
77
/// </summary>
8-
/// <typeparam name="TEnum"></typeparam>
8+
/// <typeparam name="TEnum">State Enum Type</typeparam>
99
public class EnumState<TEnum> : IState where TEnum : struct, Enum
1010
{
1111
/// <summary>
@@ -21,13 +21,13 @@ public class EnumState<TEnum> : IState where TEnum : struct, Enum
2121
/// <summary>
2222
/// Initializes a new instance of the <see cref="EnumState{TEnum}"/> class with the specified enumeration value.
2323
/// </summary>
24-
/// <param name="value"></param>
24+
/// <param name="value">Enum state value</param>
2525
public EnumState(TEnum value) => Value = value;
2626

2727
/// <summary>
2828
/// Returns a string representation of the state, which is its name.
2929
/// </summary>
30-
/// <returns></returns>
30+
/// <returns>String representation of state</returns>
3131
public override string ToString() => Name;
3232
}
3333
}

src/FsmNet/EnumStateMachineDefinition.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
/// <summary>
88
/// Represents a state machine definition based on an enumeration type.
99
/// </summary>
10-
/// <typeparam name="TEnum"></typeparam>
11-
/// <typeparam name="TContext"></typeparam>
10+
/// <typeparam name="TEnum">State Enum Type</typeparam>
11+
/// <typeparam name="TContext">Context Type</typeparam>
1212
public class EnumStateMachineDefinition<TEnum, TContext> : IStateMachineDefinition<TContext> where TEnum : struct, Enum
1313
{
1414
/// <summary>
1515
/// The type of work item this state machine is associated with.
1616
/// </summary>
17-
public string WorkItemType { get; }
17+
public string EntityType { get; }
1818

1919
/// <summary>
2020
/// A collection of all states in the state machine, represented as <see cref="IState"/> instances.
@@ -34,13 +34,13 @@ public class EnumStateMachineDefinition<TEnum, TContext> : IStateMachineDefiniti
3434
/// <summary>
3535
/// Initialize a new instance of the <see cref="EnumStateMachineDefinition{TEnum, TContext}"/> class.
3636
/// </summary>
37-
/// <param name="workItemType"></param>
37+
/// <param name="entityType">Entity type name, example: Order, Bug, etc.</param>
3838
/// <param name="states"></param>
3939
/// <param name="transitions"></param>
4040
/// <param name="initialState"></param>
41-
public EnumStateMachineDefinition(string workItemType, IEnumerable<TEnum> states, IEnumerable<ITransition<TContext>> transitions, TEnum initialState)
41+
public EnumStateMachineDefinition(string entityType, IEnumerable<TEnum> states, IEnumerable<ITransition<TContext>> transitions, TEnum initialState)
4242
{
43-
WorkItemType = workItemType;
43+
EntityType = entityType;
4444
States = states.Select(s => new EnumState<TEnum>(s)).ToList();
4545
Transitions = transitions;
4646
InitialState = new EnumState<TEnum>(initialState);

src/FsmNet/EnumTransition.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
/// <summary>
66
/// Represents a transition in a finite state machine defined by an enumeration.
77
/// </summary>
8-
/// <typeparam name="TEnum"></typeparam>
9-
/// <typeparam name="TContext"></typeparam>
8+
/// <typeparam name="TEnum">State Enum Type</typeparam>
9+
/// <typeparam name="TContext">Context Type</typeparam>
1010
public class EnumTransition<TEnum, TContext> : ITransition<TContext> where TEnum : struct, Enum
1111
{
1212
/// <summary>

src/FsmNet/FiniteStateMachine.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
/// <summary>
77
/// Represents a finite state machine based on an enumeration type.
88
/// </summary>
9-
/// <typeparam name="TState"></typeparam>
10-
/// <typeparam name="TContext"></typeparam>
9+
/// <typeparam name="TState">State Enum Type</typeparam>
10+
/// <typeparam name="TContext">Context Type</typeparam>
1111
public class FiniteStateMachine<TState, TContext> : BaseStateMachine<TState, TContext> where TState : struct, Enum
1212
{
1313
private readonly EnumStateMachineDefinition<TState, TContext> _definition;
@@ -31,9 +31,9 @@ public FiniteStateMachine(EnumStateMachineDefinition<TState, TContext> definitio
3131
/// <summary>
3232
/// Gets the definition of the finite state machine.
3333
/// </summary>
34-
/// <param name="target"></param>
35-
/// <param name="context"></param>
36-
/// <returns></returns>
34+
/// <param name="target">Target state</param>
35+
/// <param name="context">Context object</param>
36+
/// <returns>If transition to target state is allowed</returns>
3737
public override bool CanTransitionTo(TState target, TContext context) =>
3838
_definition.Transitions.Any(t =>
3939
t.From.Name == _current.Name &&
@@ -43,9 +43,9 @@ public override bool CanTransitionTo(TState target, TContext context) =>
4343
/// <summary>
4444
/// Attempts to transition to the specified target state given the current context.
4545
/// </summary>
46-
/// <param name="target"></param>
47-
/// <param name="context"></param>
48-
/// <returns></returns>
46+
/// <param name="target">Target state</param>
47+
/// <param name="context">Context object</param>
48+
/// <returns>If transtion to target state is successful</returns>
4949
public override bool TryTransitionTo(TState target, TContext context)
5050
{
5151
var transition = _definition.Transitions.FirstOrDefault(t =>

src/FsmNet/FiniteStateMachineBuilder.cs

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@
88
/// <summary>
99
/// Builder for creating a finite state machine based on an enumeration type.
1010
/// </summary>
11-
/// <typeparam name="TState"></typeparam>
12-
/// <typeparam name="TContext"></typeparam>
11+
/// <typeparam name="TState">State Enum Type</typeparam>
12+
/// <typeparam name="TContext">Context Type</typeparam>
1313
public class FiniteStateMachineBuilder<TState, TContext> where TState : struct, Enum
1414
{
15-
private readonly string _workItemType;
15+
private readonly string _entityType;
1616
private TState? _initial;
1717
private readonly HashSet<TState> _states = new HashSet<TState>();
1818
private readonly List<ITransition<TContext>> _transitions = new List<ITransition<TContext>>();
1919

2020
/// <summary>
21-
/// Initializes a new instance of the <see cref="FiniteStateMachineBuilder{TState, TContext}"/> class with the specified work item type.
21+
/// Initializes a new instance of the <see cref="FiniteStateMachineBuilder{TState, TContext}"/> class with the specified entity type.
2222
/// </summary>
23-
/// <param name="workItemType"></param>
24-
private FiniteStateMachineBuilder(string workItemType) => _workItemType = workItemType;
23+
/// <param name="entityType"></param>
24+
private FiniteStateMachineBuilder(string entityType) => _entityType = entityType;
2525

2626
/// <summary>
27-
/// Creates a new instance of the <see cref="FiniteStateMachineBuilder{TState, TContext}"/> for the specified work item type.
27+
/// Creates a new instance of the <see cref="FiniteStateMachineBuilder{TState, TContext}"/> for the specified entity type.
2828
/// </summary>
2929
/// <param name="workItemType"></param>
3030
/// <returns></returns>
@@ -63,7 +63,7 @@ public TransitionBuilder AddTransition(TState from, TState to)
6363
public EnumStateMachineDefinition<TState, TContext> Build()
6464
{
6565
if (_initial is null) throw new InvalidOperationException("Initial state not specified.");
66-
return new EnumStateMachineDefinition<TState, TContext>(_workItemType, _states, _transitions, _initial.Value);
66+
return new EnumStateMachineDefinition<TState, TContext>(_entityType, _states, _transitions, _initial.Value);
6767
}
6868

6969
/// <summary>
@@ -76,7 +76,7 @@ public SerializableStateMachine ToSerializable()
7676
if (_initial is null) throw new InvalidOperationException("Initial state must be defined.");
7777
return new SerializableStateMachine
7878
{
79-
EntityType = _workItemType,
79+
EntityType = _entityType,
8080
InitialState = _initial.ToString(),
8181
States = _states.Select(s => s.ToString()).ToList(),
8282
Transitions = _transitions.Select(t => new SerializableTransition
@@ -102,33 +102,59 @@ public class TransitionBuilder
102102
private string _conditionName;
103103
private string _sideEffectName;
104104

105+
/// <summary>
106+
/// Initializes a new instance of the <see cref="TransitionBuilder"/> class with the specified parent builder and states.
107+
/// </summary>
108+
/// <param name="parent"></param>
109+
/// <param name="from"></param>
110+
/// <param name="to"></param>
105111
public TransitionBuilder(FiniteStateMachineBuilder<TState, TContext> parent, TState from, TState to)
106112
{
107113
_parent = parent;
108114
_from = from;
109115
_to = to;
110116
}
111117

118+
/// <summary>
119+
/// Defines a condition for the transition. The condition is a function that takes the context and returns a boolean indicating whether the transition can occur.
120+
/// </summary>
121+
/// <param name="condition"></param>
122+
/// <param name="name"></param>
123+
/// <returns></returns>
112124
public TransitionBuilder When(Func<TContext, bool> condition, string name = null)
113125
{
114126
_condition = condition;
115127
_conditionName = name;
116128
return this;
117129
}
118130

131+
/// <summary>
132+
/// Defines a side effect for the transition. The side effect is an action that takes the context and is executed when the transition occurs.
133+
/// </summary>
134+
/// <param name="effect"></param>
135+
/// <param name="name"></param>
136+
/// <returns></returns>
119137
public TransitionBuilder WithSideEffect(Action<TContext> effect, string name = null)
120138
{
121139
_sideEffect = effect;
122140
_sideEffectName = name;
123141
return this;
124142
}
125143

144+
/// <summary>
145+
/// Finalizes the transition definition and adds it to the parent finite state machine builder's list of transitions.
146+
/// </summary>
147+
/// <returns></returns>
126148
public FiniteStateMachineBuilder<TState, TContext> Done()
127149
{
128150
_parent._transitions.Add(new EnumTransition<TState, TContext>(_from, _to, _condition, _sideEffect, _conditionName, _sideEffectName));
129151
return _parent;
130152
}
131153

154+
/// <summary>
155+
/// Implicitly converts the TransitionBuilder to a FiniteStateMachineBuilder, allowing for method chaining.
156+
/// </summary>
157+
/// <param name="b"></param>
132158
public static implicit operator FiniteStateMachineBuilder<TState, TContext>(TransitionBuilder b) => b.Done();
133159
}
134160

src/FsmNet/IStateMachine.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
/// <summary>
66
/// Interface for a state machine that defines the core functionality for transitioning between states.
77
/// </summary>
8-
/// <typeparam name="TState"></typeparam>
9-
/// <typeparam name="TContext"></typeparam>
8+
/// <typeparam name="TState">State Enum Type</typeparam>
9+
/// <typeparam name="TContext">Context Type</typeparam>
1010
public interface IStateMachine<TState, TContext> where TState : struct, Enum
1111
{
1212
/// <summary>

src/FsmNet/IStateMachineDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public interface IStateMachineDefinition<TContext>
1111
/// <summary>
1212
/// Gets the type of work item this state machine is associated with.
1313
/// </summary>
14-
string WorkItemType { get; }
14+
string EntityType { get; }
1515

1616
/// <summary>
1717
/// Gets a collection of all states in the state machine.

src/FsmNet/ITransition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/// <summary>
66
/// Represents a transition between two states in a finite state machine.
77
/// </summary>
8-
/// <typeparam name="TContext"></typeparam>
8+
/// <typeparam name="TContext">Context Type</typeparam>
99
public interface ITransition<TContext>
1010
{
1111
/// <summary>

src/FsmNet/Serialization/TransitionRegistry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/// <summary>
77
/// Represents a registry for conditions and side effects associated with transitions in a state machine.
88
/// </summary>
9-
/// <typeparam name="TContext"></typeparam>
9+
/// <typeparam name="TContext">Context Type</typeparam>
1010
public class TransitionRegistry<TContext>
1111
{
1212
/// <summary>

0 commit comments

Comments
 (0)