The non-generic type Type does not expect type arguments

瘦欲@ 提交于 2019-12-08 05:22:28

问题


I am creating a simple test type provider.

I want to provide a string, and return a type with the type name equal to that provided string.

But the result doesn't work, saying that BasicProvider is a non-generic type.

Error:

The non-generic type 'SimpleStringProvider.BasicProvider' does not expect any type arguments, but here is given 1 type argument(s)

module SimpleStringProvider

open ProviderImplementation
open ProviderImplementation.ProvidedTypes
open Microsoft.FSharp.Core.CompilerServices
open System.Reflection

[<TypeProvider>]
type BasicProvider (config : TypeProviderConfig) as this =
    inherit TypeProviderForNamespaces (config)

    let ns = "SimpleStringProvider.StringProvider"
    let asm = Assembly.GetExecutingAssembly()

    let staticParams = [ProvidedStaticParameter("value", typeof<string>)]

    let createTypes () =

        let myType = ProvidedTypeDefinition(asm, ns, "StringProvider", Some typeof<obj>)
        // let myProp = ProvidedProperty("MyProperty", typeof<string>, isStatic = true, getterCode = (fun args -> <@@ "Hello world" @@>))
        // myType.AddMember(myProp)
        let instantiationFunction _ paramValues =
                let typeName = (paramValues |> Array.head).ToString()
                ProvidedTypeDefinition(
                        asm,
                        ns,
                        typeName,
                        Some typeof<obj>
                    )

        do myType.DefineStaticParameters(
            parameters = staticParams,
            instantiationFunction = instantiationFunction
            )
        do this.AddNamespace(ns, [myType])

[<assembly:TypeProviderAssembly>]
do ()

Here is how I test it in a script:

#r @".\src\bin\Debug\netstandard2.0\SimpleStringProvider.dll"


open SimpleStringProvider

type X = SimpleStringProvider.BasicProvider<"test">

来源:https://stackoverflow.com/questions/50374929/the-non-generic-type-type-does-not-expect-type-arguments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!