首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TypeProvider提供了意外的开发时间行为

TypeProvider提供了意外的开发时间行为
EN

Stack Overflow用户
提问于 2016-05-10 02:16:04
回答 1查看 76关注 0票数 3

我正在摆弄我的新的静态参数化类型提供程序,它提供了一个具有静态参数化静态方法的类型。我还没有找到关于这是不被允许的文档。我得到了一些奇怪的类型提供程序行为:

这个使用类型提供程序的代码可以正确运行,但intellisense提供的信息很糟糕。成员只是不断增加,但从来没有删除。如果没有类型参数,OpDef方法应该是不可用的,但intellisense将其显示为一个选项,但如果我实际引用它,它仍然会给出一个关于缺少调用器的错误。所提供的OpDef方法的必需参数没有显示--总是显示OpDef() -> unit,而不是我目前期望看到的OpDef(suffix : string * id : string) -> unit (从类型提供程序的这个草案中)。但当我给出了它真正需要的所有论据后,它就不再抱怨了。

我做的是不受支持或不正确的事情吗?或者,有疑问的是,f#中是否存在错误(您能找出明显的错误所在)吗?

下面是使用初学者包文件的完整实现。

代码语言:javascript
复制
namespace OfflineSql

open ProviderImplementation.ProvidedTypes
open Microsoft.FSharp.Core.CompilerServices
open System.Text.RegularExpressions

#nowarn "0025"

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

    let ns = "OfflineSql"
    let asm = System.Reflection.Assembly.GetExecutingAssembly()

    let buildDomainProvider nm schema invariants =
        let parameterizedType = ProvidedTypeDefinition(asm, ns, nm, None)
        let m = ProvidedMethod("OpDef", list.Empty, typeof<unit>, IsStaticMethod = true)
        m.DefineStaticParameters(
            [
                ProvidedStaticParameter("script", typeof<string>)
            ],
            fun nm [| :? string as operation |] -> 
                let results = 
                    Regex.Matches(operation, "@([a-zA-Z_][a-zA-Z0-9_]*)") |> Seq.cast
                    |> Seq.map (fun (regmatch: Match) -> regmatch.Groups.[1].Captures.[0].ToString())
                let ps = [ for a in results -> ProvidedParameter(a, typeof<string>) ] |> List.distinct
                let opDef = ProvidedMethod(nm, ps, typeof<unit>, IsStaticMethod = true, InvokeCode = (fun _ -> <@@ () @@>))
                opDef.AddXmlDoc("Constructs a guarded method for the operation's script")
                parameterizedType.AddMember(opDef)
                opDef)
        let schemaProp = 
            ProvidedProperty("Schema", typeof<string>, IsStatic = true, 
                GetterCode = (fun _ -> <@@ schema @@>))
        let invariantsProp = 
            ProvidedProperty("Invariants", typeof<string>, IsStatic = true, 
                GetterCode = (fun _ -> <@@ invariants @@>))
        parameterizedType.AddMember(m)
        parameterizedType.AddMember(schemaProp)
        parameterizedType.AddMember(invariantsProp)
        parameterizedType

    do
        let root = ProvidedTypeDefinition(asm, ns, "Domain", None)
        root.DefineStaticParameters(
            [
                ProvidedStaticParameter("schema", typeof<string>)
                ProvidedStaticParameter("invariants", typeof<string>, "")
            ],
            fun nm [| :? string as schema ; :? string as invariants |] -> 
                buildDomainProvider nm schema invariants)
        this.AddNamespace(ns, [ root ])

[<assembly:TypeProviderAssembly>]
do ()
EN

回答 1

Stack Overflow用户

发布于 2016-05-10 07:14:10

这与带有修复的已知错误直接相关:

感谢@gauthier在functionalprogramming.slack.com/fsharp上的这个发现。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37122707

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档