Background
I am learning about generative type providers.
I used Cameron Taggart's VectorTP example from here and here. In that code he builds up the C# code for a vector class that has a design-time specified number of properties, compiles it, and returns the generated type. It worked well.
For example, this client code compiles and runs:
type Vector2D = Vector<"X", "Y">
let v1 = Vector2D()
v1.X <- 3.14
v1.Y <- 2.91
And if you look at what is going on inside the type provider code at design-time, you see that the type provider code is being called like this:
ITypeProvider.ApplyStaticArguments(
VectorTP.Vector, // typeWithoutArguments
[|"ConsoleApplication8"; "Vector2D"|], // typeNameWithArguments
[|"X"; "Y"; ""; ""; ""; ""; ""|]) // staticArguments
That all looks good.
Problem
This client code does not compile:
type Vector2D = Vector<"X", "Y">
let list = System.Collections.Generic.List<Vector2D>()
This time, if you look at what is going on inside the type provider code at design-time, you see this additional call when the List<Vector2D>
is added to the client code:
ITypeProvider.ApplyStaticArguments(
Mindscape.Vectorama.Vector2D, // typeWithoutArguments
[|"Vector2D,"|], // typeNameWithArguments
[|""; ""; ""; ""; ""; ""; ""|]) // staticArguments
It appears that the type provider framework (is that the right term?) is calling ITypeProvider.ApplyStaticArguments
asking for a generated type based on Vector2D
without any static arguments. But, Vector2D
is already the generated type?!
The VectorTP example does not properly handle this case, and so the client code will not compile.
Note
I did try moving the type Vector2D = Vector<"X", "Y">
declaration into a separate DLL and then referencing that DLL. Of course, that worked as expected. The generated Vector2D
class simply looks like any other type at that point.
The complication seems to be with generating the type and using it as generic parameter in the same assembly (or script, through I have not tried that).
Questions
Is this a problem in the "type provider framework"? Or is this the expected behavior?
Why is
ApplyStaticArguments
being called when I use the generated type as a generic type parameter?If the
ITypeProvider
is supposed to handle this case, what is the proper response?