I have a base class with explicit generic arguments in F#. I’m trying to check if the given type I’m using implements a specific interface. I thought “if ob 😕 ISysAware then” would do, but the complain is always the same:
let (|SysAware|_|) t =
match t with
| :? ISysAware as p -> Some(p)
| _ -> None
error FS0008: This runtime coercion or type test from type ‘a to ISysAware involves an indeterminate type based on information prior to this program point. Runtime type tests are not allowed on some types. Further type annotations are needed.
I’d prefer not to use reflection here, obviously. IsAssignableFrom would do the trick, at a high cost.
Thoughts?
Some F# types are value types; adding
boxensures that type test is performed on reference types only: