【发布时间】:2014-01-31 23:06:22
【问题描述】:
我创建了一个简单的类型提供程序,我想在程序集中公开一些预生成的类型,如下所示:
[<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,它正在尝试做类似于我正在做的事情。不幸的是,在我的机器上,该提供程序的行为与我的相同,即它为命名空间提供 Intellisense,但不为类型提供。所以我不知道它是否可能是我的配置特有的东西还是什么。
【问题讨论】:
-
你用Reflector或者你最喜欢的反汇编工具打开了组件吗?可能值得一看。
-
这里是类似问题的答案stackoverflow.com/questions/15078419/…
-
更新了问题并提供了更多信息。
标签: f# type-providers