Reputation: 42246
I want to access F# signature data from a compiled F# dll.
I understand that I can get the signature data from the source files using the FSharp.Compiler.Service library. I could not find a way to use that library to produce signature information from a dll without sources.
I see two options, but I think it's possible there may be a simpler solution. The two options I'm aware of are:
Embed the F# source code in the dll and use FSharp.Compiler.Service to extract information from the embedded resource. I could then make any associations to reflection metadata from correspondence in name. Unless I did something wrong, FSharp.Compiler.Service can't interpret an .fsi signature file, so it seems that the whole source would need to be embedded for this to work.
Reconstruct the F# signature from reflection metadata. This approach seems necessarily insufficient because some data is not recoverable through reflection (e.g. type aliases).
My question is:
Is there a better way to access F# signature data and associate it with reflection metadata than I have suggested?
Another way to look at this question that might make it a little more concrete is, "Given a compiled F# assembly, how can I determine all the type aliases (and referents thereof) that would be available to referencing projects?"
Upvotes: 2
Views: 226
Reputation: 243041
This is essentially what the Library documentation part of F# Formatting does. It generates documentation from a compiled DLL (together with the XML comments), but the key part is that it loads the metadata about the F# code from the compiled DLL.
The way it works is that it uses the F# Compiler Service to build a project
It uses the F# Compiler Service to load the compiled F# DLL (as if you were referencing it when compiling some code). The F# compiler service then sees all the information about the DLL, including things like aliases (that's what the F# compiler itself sees when you reference a DLL!)
The source code for it is on GitHub - good starting point is the call to FSharpAssembly.LoadFiles
here, which reads the meta-data that is later processed.
Upvotes: 4