Sunday, September 9, 2012

DGML Type Provider - Explore Designer support for F#

When waiting for the test result for my symbol add-on in the tranquility of Saturday night, I suddenly realized that the DGML file in Visual Studio can be used to design a state machine. My idea is simple. Use DGML represent a state machine and use type provider to generate some code for me. Sort of designer support for F#. Only the color is not perfect, but it is better than nothing.. :-)

I did a library to process any DGML file. The library serves as the base class for the type provider and the type provider can help me generate some code. I made up a prototype and the source code is check in at  F# sample pack. (on Sep 9, 2012 2:17 AM). You can go to "source" and the type provider is under SampleProvider folder.

The DGML file is shown in Visual Studio like:

And the transition code is like:

// set the transition functions
t.SetFunction(t.State0, printObj)
t.SetFunction(t.State1, printObj)
t.SetFunction(t.State2, printObj)
t.SetFunction(t.State3, printObj)
// valid transitions
// invalid transition

Please leave your comments.. :)

No comments: