I\'m trying to pattern match against a few types that I care about for SQL generation. Ideally I\'d like to do this:
let rec getSafeValue record (prop: Prope
When I put your code in F# Interactive, it seems to make 'record' a generic param. Maybe it works differently in the normal compiler. Anyway, it is probably picking up that obj type due to the first argument of GetValue being type obj.
I'm sorry I can't test this right now, but give this a shot. The box function uses a generic param, so that might do the trick.
let rec getSafeValue record (prop: PropertyInfo) =
match prop.GetValue(box record, null) with
| :? string as str -> "'" + str + "'"
| :? Option<_> as opt ->
match opt with
| Some v -> getSafeValue v prop
| None -> "null"
| _ as v -> v.ToString()