Are there any pitfall I should be aware of doing so ?
Would you know of existing code dealing with the same pb I might encounter ?
Thks
Unfortunately, you cannot pass types as static parameters to a type provider. The static parameters passed using MyProvider< "first argument", 42 >
have to be primitive types (like string
, int
and similar). I don't see the list anywhere in the documentation, but Type
is definitely not supported.
The problem with doing this is that you could pass it typeof<MyType>
where MyType
is declared in the same file as the file that's using the type provider, and so the F# compiler would have to first compile the first part of a file, then invoke the provider and then continue. This sounds possible, but it is probably low-priority for the F# team.
The best way to pass information about type to a type provider is to give it a type name and then lookup the type using reflection (this will only work if the type is from an already compiled assembly):
type MyTest = MyTypeProvider<"System.Int32">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With