Pergunta

I am using F# Type Provider function to expose the entire data of my system. When retrieving the query string from the user, the type provider initiates connection to remote server and parse the DataTable returned into strong-typed data. Currently, I have faced an issue like chicken-and-egg problem.

The ProvidedMethod can be initialized like this:

let queryParam = ProvidedParameter("queryString", typeof<string>)
let method = ProvidedMethod("Query", [queryParam], returnType,
                            InvokeCode = (fun args -> <@@ .. @@>))

I need to declare the type of the return data right when I declare this method. But I can only determine this type when I have the query string and fetch column metadata of that DataTable and create another ProvidedTypeDefinition then populate with corresponding ProvidedProperty for each column.

So my question is that, is there any way to solve this? Is any of the approaches below possible ?

  • Set a placeholder for the return type and replace this type inside the InvokeCode (I dont know if we can do this in F#)
  • Retrieve the query string from queryParam and create the type then pass the type as parameter of ProvidedMethod

If not, please suggest walk around for this case.

Foi útil?

Solução

That's not how type providers work - provided methods can't have return types which vary based on input values.

However, what you can do is use your query string as a static parameter to the type provider itself, and then expose a method with a signature that depends on the compile-time argument. Many of the documented examples use exactly this technique (see e.g. the section titled "A Type Provider That Uses Static Parameters" here).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top