-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathtest-api.fsx
More file actions
31 lines (27 loc) · 1010 Bytes
/
test-api.fsx
File metadata and controls
31 lines (27 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#r "nuget: Fantomas.FCS, 7.0.5"
open System
open Fantomas.FCS
open Fantomas.FCS.Text
open Fantomas.FCS.Syntax
open Microsoft.FSharp.Reflection
let code = "let x = 1"
let ast, _ = Parse.parseFile false (SourceText.ofString code) []
let rec findConst (indent: int) (x: obj) =
let prefix = String.replicate indent " "
let t = x.GetType()
if FSharpType.IsUnion(t) then
let case, fields = FSharpValue.GetUnionFields(x, t)
if case.Name = "Const" then
printfn "%sFound Const!" prefix
fields |> Array.iteri (fun i f ->
if isNull f then
printfn "%s Field %d: NULL" prefix i
else
let fType = f.GetType()
printfn "%s Field %d: Type=%s Value=%s" prefix i fType.Name (f.ToString())
)
fields |> Array.iter (fun f ->
if not (isNull f) && FSharpType.IsUnion(f.GetType()) then
findConst (indent + 1) f
)
findConst 0 ast