StateMachine in c# and xml
Yesterday I browsed through the new articles at
codeproject.com.
Leslie Sanford StateMachine articles had my attention. He has designed and implemented it in c#. A job done pretty well I think. I took a look at his code that reads an xml definition to deserialize its state design. My thoughts were that it wasn't really readable and logical so I made a class design that serializes to a "self-describing" xml document.
An example:
<?xml version="1.0"?>
<Machine Id="Switch" InitialState="On" xmlns="Exyll.StateMachine">
<SubStates>
<State Id="On">
<Transitions>
<Transition EventName="TurnOff" Target="Off" />
</Transitions>
</State>
<State Id="Off">
<Transitions>
<Transition EventName="TurnOn" Target="On" />
</Transitions>
</State>
</SubStates>
<Events>
<Event>TurnOff</Event>
<Event>TurnOn</Event>
</Events>
</Machine>
If you are interested in this class design and the xmlattributes I had to add to achieve this xml format then download
StateMachine code.