How to get 'System.Type' of the module?
For example module:
module Foo =
let bar = 1
And this does not work:
printfn "%s" typeof<Foo>.Name
Error is:
The type 'Foo' is not defined
How to get 'System.Type' of the module?
For example module:
module Foo =
let bar = 1
And this does not work:
printfn "%s" typeof<Foo>.Name
Error is:
The type 'Foo' is not defined
You could add a marker type to the module and then discover the module's type from that:
module name is not a type.
List
inList.map
andlet (a:List<int>) = [1;2;3]
are different.The first
List
is a module name, the second is a type.It would certainly be nice to have a
moduleof
operator... Since there's not one, the easiest way to do what you want is probably to use the Metadata library in the F# PowerPack:Unfortunately, this won't work with dynamic assemblies (such as those generated via F# Interactive). You can do something similar using vanilla
System.Reflection
calls, but that's more dependent on having a good understanding of the compiled form that your module takes.It can also be done using Quotations. First, define this helper function somewhere:
Then, you can define a module and get its type like this:
Hope this helps.