let foo = None
In the above example, is there a way in FSharp or FSharp Compiler Services to determine if foo is an Option type without resorting to reflection?
I tried the following function but I'm getting a System.InvalidOperationException: 'the type 'obj' does not have a qualified name' error when accessing the fsharpType.TypeDefinition.FullName property in the code below.
let private isOptionType (fsharpType:FSharpType) =
if fsharpType.HasTypeDefinition then
let fullnme = fsharpType.TypeDefinition.FullName
match fsharpType.TypeDefinition.TryFullName with
| Some fullName -> (Type.GetType fullName).GetGenericTypeDefinition() = typedefof<Option<_>>
| None -> false
else
false
let private checkOptionType (checkFile:FSharpCheckFileResults) = fun () ->
let partialAssemblySignature = checkFile.PartialAssemblySignature
let moduleEntity = partialAssemblySignature.Entities.[0]
let fnVal = moduleEntity.MembersFunctionsAndValues.[0]
isOptionType fnVal.FullType