具有可移植库的F#类型提供程序 [英] F# type providers with Portable Library

查看:68
本文介绍了具有可移植库的F#类型提供程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建Windows 8应用程序,发现自己想要包含 ISO-4217 代码,我使用的是最新的XML格式.

I'm building a Windows 8 application and am finding myself wanting to include a list of ISO-4217 codes, which I have in up-to-date form in XML.

自然,所有国家/地区都有一些这样的代码.我认为类型提供者将是一个很好的选择.但是,由于它们发出代码,所以我不能将它们与可移植库一起使用.

Naturally, there are a couple of these codes for all countries. I figured a Type Provider would be an excellent fit. However, since they emit code, I can't use them with Portable Libraries.

如何使用我有XML ?

推荐答案

我没有创建可在便携式库中使用的类型提供程序的经验,但是您似乎假设类型提供程序会在处发出代码运行时.这实际上是不正确的,因此在便携式"设置中使用它们可能会更容易.

I don't have experience with creating a Type Provider that is useable from Portable Libraries, but you seem to be assuming that type providers emit code at runtime. This is not actually true and so using them in Portable setting might be easier.

当运行F#编译器时,将执行类型提供程序.此时,它可能会生成一些类型,尽管实际上只有一种类型提供程序会这样做(有两种不同的类型-请参见

The type provider is executed when you run the F# compiler. At this point, it may generate some types, although only one kind of type providers actually does that (there are two different kinds - see this SO answer). However, when you compile code that uses an F# type provider, the resulting assembly does not emit any code at runtime.

我认为 Freebase类型提供程序(在FSharpX中可用)是在可移植模式下工作的提供程序的示例.我怀疑技巧的一部分是将提供程序拆分为两个程序集-一个包含运行时所需的代码,另一个包含设计时组件(用于构建)类型信息,尽管它们也不需要发出).请参见 FreebaseRuntime.fs .

I think the Freebase type provider (available in FSharpX) is an example of a provider that works in Portable mode. I suspect that a part of the trick is to split the provider into two assemblies - one that contains code that is needed at runtime and another that contains design time components (which build type information, although they also do not need emit). See TypeProviderAssembly attribute in FreebaseRuntime.fs.

这篇关于具有可移植库的F#类型提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆