fsharp / fsharp/fslang-suggestions
Allow typeof<module Module> or something equivalent
- Dominant language
- No language data
- Stars
- 373
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Description
I propose a mechanism is added to allow us to get the CLR type of a module as easily as it is for normal types with typeof<>.
This is to solve two recurring situations we have in our code base that we currently have to workaround.
The first is logger factory methods expect a CLR type to be passed in to set their context. We currently workaround this by declaring a private dummy types in modules so that we can do typeof.GetDeclaringType() to get the module type to pass to the logger.
The second is reflection based tests that check our api hasn't changed between builds, most of our tests just do typeof.Assembly to pass to the api checker, but projects with only modules in them have to instead Assembly.Load("Module").
Initial ideas for this are to somehow extend typeof<> to allow module names to be passed in, or via a new keyword like moduleof<>.
## Pros and Cons
The advantages of making this adjustment to F# are we'll no longer need workarounds to get the CLR type of modules. This would trim a significant amount of boilerplate, and also stop new F#ers hitting this confusing limitation.
The disadvantages of making this adjustment to F# are that this may be a breaking change based on how it's decided to implement it.
## Extra information
Estimated cost (XS, S, M, L, XL, XXL): S-M
Related suggestions: I found no related suggestions.
## Affidavit (please submit!)
Please tick this by placing a cross in the box:
* [X] This is not a question (e.g. like one you might ask on [stackoverflow](http://stackoverflow.com)) and I have searched stackoverflow for discussions of this issue
* [X] I have [searched both open and closed suggestions on this site](http://github.com/fsharp/fslang-suggestions/issues) and believe this is not a duplicate
* [X] This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.
Please tick all that apply:
* [ ] This is not a breaking change to the F# language design
* [X] I or my company would be willing to help implement and/or test this
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.