Reputation: 11477
I am getting a bunch of objects from an F# assembly, which I am then reflecting over to discover their value.
(To be precise I have a parser using fsYacc. I am then trying to display the results of the parse in a TreeView.)
One of the possible objects returned is this Discriminated union :
type op = Eq | Gt | Ge | Lt | Le
An object of this type will have a value, say Ge
.
Is there any way using reflection that I can determine that an object is a Discriminated union, and hence take steps to determine its value?
Upvotes: 1
Views: 233
Reputation: 25516
To determine if it is a disriminated union - http://msdn.microsoft.com/en-us/library/ee353623.aspx - FSharpType.IsUnion
To get value use Reflection.UnionCaseInfo
- http://msdn.microsoft.com/en-us/library/ee370473.aspx
Upvotes: 5