gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 19:02:22 25 4
gpt4 key购买 nike

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

[<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.

我做错了什么?

更新:根据 Dmitry 的建议,我查看了 related question并下载了 associated type provider那是试图做一些类似于我正在做的事情。不幸的是,在我的机器上,该提供程序的行为与我的相同,即它为命名空间提供智能感知,但不为类型提供智能感知。所以我不知道这是否是我的配置特定的问题。

最佳答案

嗯,这不是我的代码。事实证明,当我使用链接示例中包含的确切 ProvidedTypes-head.fs 时,一切都会正常工作。但是,当我使用不同的版本(例如 FSharp.Data 中的 ProvidedTypes.fs)时,它会出现不正确的行为。我不确定它们之间的区别是什么导致了这个问题。我也不确定在哪里可以找到该文件的“官方”版本(如果确实存在)。

更新:看起来正式版本是here .

关于f# - Intellisense 不适用于 F# 类型提供程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21459160/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com