F# type providers with Portable Library

2019-05-05 03:54发布

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.

How do I compile the type provider so that it doesn't use emit, in order to use the XML I've got?

2条回答
男人必须洒脱
2楼-- · 2019-05-05 04:06

XmlProvider from FSharp.Data works with portable libraries

查看更多
疯言疯语
3楼-- · 2019-05-05 04:12

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.

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.

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.

查看更多
登录 后发表回答