open Microsoft.FSharp.Reflection
type PtRespType = |Deductible |CoPay |CoInsurance with override x.ToString() = match x with |CoInsurance -> "CoIns" | _ -> sprintf "%A" x
type PaymentItemType = |EraPayment |EraAdjustment of bool | PtResp of PtRespType | OtherPayment
|EraPayment _ -> "EraPayment"
|EraAdjustment _ -> "EraAdjustment"
|PtResp pt -> sprintf "PtResp%O" pt
let cases = FSharpType.GetUnionCases(typeof<PaymentItemType>)
match c.GetFields() |> List.ofSeq with
if FSharpType.IsUnion x.PropertyType then
FSharpType.GetUnionCases(x.PropertyType)
|> Seq.map (fun uc -> FSharpValue.MakeUnion(uc, Array.empty))
|> Seq.map (fun uc -> FSharpValue.MakeUnion(c, [| uc |] ))
elif x.PropertyType = typeof<bool> then
[FSharpValue.MakeUnion(c, [| box false |])]
[FSharpValue.MakeUnion(c, Array.empty)]
| _ -> [ FSharpValue.MakeUnion(c, Array.empty)]
|> Seq.cast<PaymentItemType>
let rec fDesired (fNonUnion:Type -> obj) (t:Type) =
fDesired (fun t -> if t = typeof<bool> then box false else null) typeof<PaymentItemType>