Question

I'm trying to implement a typeprovider using the examples I found in different places.

What I want is to be able to create a constructor which assigns the provided arguments to the right properties. The result will have do the same thing as the type below.

type SomeType(arg1: int, arg2: string) = 
    member this.Arg1 = arg1
    member this.Arg2 = arg2

I've tried different approaches, but I just can't get passed the first argument in the args list.

ProvidedConstructor(
    parameters = parameters, 
    InvokeCode = (fun args -> ??)

What kind of code must be invoked to achieve this. Or do I have to take another approach?

Était-ce utile?

La solution

What will be the underlying runtime representation of your provided type (the type you passed to the ProvidedTypeDefinition baseType argument)? The ProvidedConstructor InvokeCode is a function that takes a list of expressions and returns an expression of the underlying type. For example, if the runtime representation is a 2-element tuple, InvokeCode would be something like this:

InvokeCode = (fun [arg1;arg2] -> <@@ (%%arg1:int), (%%arg2:string) @@>)

Make sure to read this tutorial

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top