Thursday, May 07, 2015

Getting the types in an F# union type

This arose in the context of performing data contract serialization of a union type, and needing to feed the concrete types in as known types. As the FSharp.Reflection facilities only let you at the names of the union cases, it's necessary to rely on the secret knowledge that the union cases are implemented as nested subtypes of the abstract union type



Then we can serialize objects of the union type like



where we feed the list of types to be known to the constructor for the serializer.


Post a Comment