Intellisense不适用于F#类型提供程序

时间:2014-01-30 14:28:25

标签: f# type-providers

我创建了一个简单的类型提供程序,我希望在程序集中公开一些预生成的类型,如下所示:

[<TypeProvider>]
type TestProvider() as this =
    inherit TypeProviderForNamespaces()
    let providedType = ProvidedTypeDefinition(Assembly.GetExecutingAssembly(), "Test", "TypeLib", None)
    do let assembly = Assembly.LoadFrom @"C:\Some\Long\Path\TestTypes.dll"
       // Get same problem with providedType.AddAssemblyTypesAsNestedTypesDelayed(),
       // which is what I really want to use
       providedType.AddMember(assembly.GetType("TestTypes.Circle"))
       this.AddNamespace("Test", [providedType])

我从另一个项目中使用此提供程序,如下所示:

// Circle member not showing up under TypeLib
type Circle = Test.TypeLib.Circle

let c = Circle()
c.Radius <- 4.
printfn "%f" c.Radius
System.Console.ReadKey() |> ignore

它按预期编译,运行和工作,但由于某种原因,Circle未显示在Test.TypeLib的Intellisense列表中。当我将鼠标悬停在Circle上时,它会显示A reference to type 'TestType.Circle' in assembly 'TestTypes' was found, but the type could not be found in that assembly.

我做错了什么?

更新:根据德米特里的建议,我查看了related question并下载了associated type provider,它正在尝试做类似我正在做的事情。不幸的是,在我的机器上,提供程序的行为与我的相同,即它为名称空间提供了Intellisense,但没有提供类型。所以我不知道它是否可能是我的配置特有的东西。

1 个答案:

答案 0 :(得分:1)

嗯,这不是我的代码。事实证明,当我使用链接示例中包含的确切ProvidedTypes-head.fs时,一切都会像它应该的那样工作。但是,当我使用其他版本时,例如来自ProvidedTypes.fs的{​​{1}},则其行为不正确。我不确定导致问题的是什么区别。我也不确定在哪里可以找到该文件的“官方”版本,如果确实存在的话。

更新:看起来正式版是here