If I have a module of name MyModule defined in an .fsx script and referenced from within another .fsx script; is it possible to determine at runtime if the module defines a variable foo?
I am trying to implement something like this:
let fooWithDefault =
let cfgType:Type = typedefof<MyModule>
let propOpt =
cfgType.GetProperties()
|> Seq.tryFind( fun p -> p.Name = "foo")
match propOpt with
| Some foo -> foo.GetValue(null).ToString()
| None -> "My Default Value for f"
The above attempt fails with the error:
The type 'MyModule' is not defined
Assembly.GetExecutingAssembly().GetTypes() |> Seq.find (fun t -> t.Name = "MyModule")- risk of a name collision is negligible and there are no perf worries in my use casenamespace FSI_0005prepended.