开发者

Is there a simple .NET code generator for a Event-driven finite state machine?

Is there a simple .NET code generator for a Event-driven finite state machine?

I am tired of doing this by hand for user-interface objects. I just need the enum definition, the switch statement, and each function call. I do not need a "library".

See Event-driven finite state machine at http://en.wikipedia.org/wiki/Event_driven_finite_state_machine.

State Machines in C# 3.0 using T4 Templates at http://aabs.wordpress.com/2008/06/26/state-machines-in-c-30-using-t4-templates/ seems like it is wh开发者_JAVA百科at I want but the link to the example code is broken.


If I were in your position, I would download the trial version of Enterprise Architect:

http://www.sparxsystems.com.au/products/ea/index.html

I would then model my scenario and then use the code generator. Depending on how many you need to generate you might want to look into some of the more advanced options in the product, such as scripting that might allow you to generate multiple time changing parameters based on a list.

P.S. I don't work for Sparx systems :-), I do love their tools though.


Like you said, you just need:

An enum definition, holding a variable of it, a naming convention that includes in the method name the corresponding enum state, a call with reflection and updating the variable holding the enum.

The above isn't with generated code, but I don't see why not using it. You should be able to bake one quickly. An alternative instead of using reflection, would be holding in a list for each state which Func<> will be called, and generating that should be easy with a T4 template.


ps. I tend to be a lot more helpful, but the way the question is phrased it begged for it ^-^. That said, I'm kind of serious with the above, doing either of the above isn't that much time (specially with stackoverflow help in any part the OP might not know) / and the OP wrote that like he has done those by hand tons of times.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜