Table of contents
Collapse the table of content
Expand the table of content

FSharpValue.GetUnionFields Method (F#)

Den Delimarsky|Last Updated: 8/18/2017
1 Contributor

Identify the union case and its fields for an object.

Namespace/Module Path: Microsoft.FSharp.Reflection

Assembly: FSharp.Core (in FSharp.Core.dll)


// Signature:
static member GetUnionFields : obj * Type * ?BindingFlags -> UnionCaseInfo * obj []
static member GetUnionFields : obj * Type * ?bool -> UnionCaseInfo * obj []

// Usage:
FSharpValue.GetUnionFields (value, unionType)
FSharpValue.GetUnionFields (value, unionType, bindingFlags = bindingFlags)

open FSharpReflectionExtensions
FSharpValue.GetUnionFields (value, unionType, allowAccessToPrivateRepresentation = false)


value Type: obj

The input union case.

unionType Type: System.Type

The union type containing the value.

bindingFlags Type: System.Reflection.BindingFlags

Optional binding flags.

allowAccessToPrivateRepresentation Type: bool

Optional flag that denotes accessibility of the private representation.


ArgumentExceptionThrown when the input type is not a union case value.

Return Value

The description of the union case (as a UnionCaseInfo object) and its fields.


If the type is not given, then the runtime type of the input object is used to identify the relevant union type. The type should always be given if the input object may be null. For example, option values may be represented using the null.


Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

Version Information

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

See Also

Reflection.FSharpValue Class (F#)

Microsoft.FSharp.Reflection Namespace (F#)

© 2020 Microsoft