Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
635 views
in Technique[技术] by (71.8m points)

reflection - How to get type of the module in F#

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You could add a marker type to the module and then discover the module's type from that:

module Foo =  
    type internal Marker = interface end
    let t = typeof<Marker>.DeclaringType

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...