The Type Provider Starter Pack was designed with two purposes initially. Firstly, to be a canonical repository for the ProvidedTypes files which provide a source file based API for creating type providers. And secondly, to be a set of tutorials and examples for people wanting to dip their toes into building type providers for the first time.
To be honest, it's not been doing a complete job of either:
- I think most people are using it as the source of ProvidedTypes.fs and .fsi now days, but it didn't provide any infrastructure or testing for progressing the library.
- The "examples" were limited to a link to my tutorial on building type providers
Today, that's changed. And I need your help!
Once I started thinking about it, it became clear that the code needed for basic type provider examples, and the code needed to test ProvidedTypes.fs were basically identical.
So I implemented a system for compiling and testing example .fsx scripts within the Starter Pack repository.
Want to help out? As long as you have some basic git and F# knowledge, it's easy!
Fork the repository and pull down a clone
Add an example to the
Structure the example as below and save it as an .fsx file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#if INTERACTIVE block at the top will allow you to write your example in Visual Studio, without us requiring a separate project for each example provider.
Add a set of tests in a .fsx script in the
The test file for the example above looks like this, and again should be saved as an .fsx file:
1 2 3 4 5 6 7 8 9 10 11
Note the two #r references at the top. Remember what you choose to call the dll!
Hooking up the examples so they get built and tested
The main build file is where the magic happens - build.fsx in the root directory.
Squirrelled away in there is a target called
Examples. It's contents look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
You will need to add your example to the
examples list at the top of the target.
Name is the name of the dll that will be produced for your type provider.
ProviderSourceFiles is the fsx file with your type provider example code. And
TestSourceFiles is the code of your tests.
If you check further down, the call to the compiler to compile your provider will automatically prepend the ProvidedTypes files, so there's no need to list those. And the call to the compiler to run your tests will have references added for the provider you just built and
So what are you waiting for? Get writing some examples!