If I use the F# Type Providers from the assembly FSharp.Data.TypeProviders 4.3.0.0, I am able to create types in a very simple F# library. I am then able to use those types without any dependency on the assembly FSharp.Data.TypeProviders. That is pretty sweet! Here is an example:
I created an F# library project called TryTypeProviders. I put this in the .fs:
module TryTypeProviders
type Northwind = Microsoft.FSharp.Data.TypeProviders.ODataService
I then am able to use the F# library from a C# project:
public static void Main()
{
var c = new TryTypeProviders.Northwind();
foreach (var cust in c.Customers)
Console.WriteLine("Customer is: " + cust.ContactName);
Console.ReadKey(true);
}
I haven't been able to find any working examples of how to create a type provider like this. The type providers in FSharpx.TypeProviders are not accessible from C#. My guess is that they are erased types and not generated types. I'm still a little fuzzy on which is which, but it is defined here as:
- Generated types are real .NET types that get embedded into the assembly that uses the type provider (this is what the type providers that wrap code generation tools like sqlmetal use)
- Erased types are simulated types which are represented by some other type when the code is compiled.
The samples from the F# 3.0 Sample Pack mentioned in the MSDN tutorial are not working for me. They build, but when I try to use them I get errors.
open Samples.FSharp.RegexTypeProvider
type PhoneNumberRegEx = CheckedRegexProvider< @"(?<AreaCode>^\d{3})-(?<PhoneNumber>\d{3}-\d{4}$)">
open Samples.FSharp.MiniCsvProvider
type csv = MiniCsvProvider<"a.csv">
It was last released in March of 2011 and my guess is that they don't yet reflect the final version of type providers that shipped with Visual Studio 2012.
F# Type Providers look like a great technology, but we need help building them. Any help is appreciated.