问题
I am trying to build a TypeProvider where nested ProvidedProperty
is generated based on parent's type value.
A result I want to have is following
#r @"bin/Debug/library.dll"
open Library.TypeProviders
type sdmx = SdmxDataProvider<WsEntryPoint="">
let dataflows = sdmx.GetDataFlowsContext()
let a = dataflows.A.A1 // A1,A2,A3 < should be generated based on A
let b = dataflows.B.B1 // B1,B2,B3 < should be generated based on B
let c = dataflows.C.C1 // C1,C2,C3 < should be generated based on C
I could generate all dimensionsType
s for all dataflowsType
s.
Then I tried to add argument dfId
and then use it to choose properties.
let dimensionsType dfId =
let t = ProvidedTypeDefinition("Dimensions", Some typeof<string>)
t.AddMembersDelayed (fun () ->
[ for dimension in [(1, "A1"); (1, "A2"); (1, "A3");
(2, "B1"); (2, "B2"); (2, "B3");
(3, "C1"); (3, "C2"); (3, "C3")] do
let dataflowId, dimensionName = dimension
if dataflowId = dfId then
let prop =
ProvidedProperty
( dimensionName, typeof<string>,
GetterCode = (fun args -> <@@ (%%args.[0]) :> string @@>))
yield prop
])
serviceTypesType.AddMember t
t
let dataflowsType =
let t = ProvidedTypeDefinition("Dataflows", Some typeof<string>)
t.AddMembersDelayed (fun () ->
[ for dataflow in [(1, "A"); (2, "B") ; (3, "C")] do
let dataflowId, dataflowName = dataflow
let prop = ProvidedProperty(dataflowName, dimensionsType dataflowId, GetterCode = (fun args -> <@@ (%%args.[0]) :> string @@>))
yield prop])
serviceTypesType.AddMember t
t
This approach raises error: error FS1109: A reference to the type 'Library.TypeProviders.SdmxDataProvider,WsEntryPoint="".ServiceTypes.Dimensions' in assembly 'Library' was found, but the type could not be found in that assembly
Is it possible to do this kind of type generation?
Full Source: https://gist.github.com/demonno/f9234ced664439986597cf7c3218d3b8
来源:https://stackoverflow.com/questions/53248969/f-type-provider-dependent-nested-types