Header menu logo FSharp.Core

UnionCaseInfo Type

Represents a case of a discriminated union type

Instance members

Instance member Description

this.DeclaringType

Full Usage: this.DeclaringType

Returns: Type

The type in which the case occurs.

Returns: Type
Example

 type Weather = Rainy | Sunny

 let rainy =
     typeof<Weather>
     |> FSharpType.GetUnionCases
     |> Array.head

 rainy.DeclaringType
type Weather = | Rainy | Sunny
val rainy: obj
val typeof<'T> : System.Type
module Array from Microsoft.FSharp.Collections
val head: array: 'T array -> 'T
Evaluates to a value of type System.Type that holds type information for Weather.

this.GetCustomAttributes

Full Usage: this.GetCustomAttributes

Parameters:
    attributeType : Type - The type of attributes to return.

Returns: obj array An array of custom attributes.

Returns the custom attributes associated with the case matching the given attribute type.

attributeType : Type

The type of attributes to return.

Returns: obj array

An array of custom attributes.

Example

 type Signal(signal: string) =
    inherit System.Attribute()
    member this.Signal = signal

 type Answer =
     | [<Signal("Thumbs up")>] Yes
     | [<Signal("Thumbs down")>] No

 typeof<Answer>
 |> FSharpType.GetUnionCases
 |> Array.map (fun x -> x.GetCustomAttributes(typeof<Signal>))
Multiple items
type Signal = inherit Attribute new: signal: string -> Signal member Signal: string

--------------------
new: signal: string -> Signal
val signal: string
Multiple items
val string: value: 'T -> string

--------------------
type string = System.String
namespace System
Multiple items
type Attribute = member Equals: obj: obj -> bool member GetHashCode: unit -> int member IsDefaultAttribute: unit -> bool member Match: obj: obj -> bool static member GetCustomAttribute: element: Assembly * attributeType: Type -> Attribute + 7 overloads static member GetCustomAttributes: element: Assembly -> Attribute array + 15 overloads static member IsDefined: element: Assembly * attributeType: Type -> bool + 7 overloads member TypeId: obj
<summary>Represents the base class for custom attributes.</summary>

--------------------
System.Attribute() : System.Attribute
val this: Signal
type Answer = | Yes | No
val typeof<'T> : System.Type
module Array from Microsoft.FSharp.Collections
val map: mapping: ('T -> 'U) -> array: 'T array -> 'U array
val x: obj
Evaluates to
 [|[|FSI_0147+Signal {Signal = "Thumbs up";
                      TypeId = FSI_0147+Signal;}|];
   [|FSI_0147+Signal {Signal = "Thumbs down";
                      TypeId = FSI_0147+Signal;}|]|]

this.GetCustomAttributes

Full Usage: this.GetCustomAttributes

Returns: obj array An array of custom attributes.

Returns the custom attributes associated with the case.

Returns: obj array

An array of custom attributes.

Example

 type Weather =
     | Rainy
     | Sunny

 typeof<Weather>
 |> FSharpType.GetUnionCases
 |> Array.map (fun x -> x.GetCustomAttributes())
type Weather = | Rainy | Sunny
val typeof<'T> : System.Type
module Array from Microsoft.FSharp.Collections
val map: mapping: ('T -> 'U) -> array: 'T array -> 'U array
val x: obj
Evaluates to
 [|[|Microsoft.FSharp.Core.CompilationMappingAttribute
     {ResourceName = null;
      SequenceNumber = 0;
      SourceConstructFlags = UnionCase;
      TypeDefinitions = null;
      TypeId = Microsoft.FSharp.Core.CompilationMappingAttribute;
      VariantNumber = 0;}|];
 [|Microsoft.FSharp.Core.CompilationMappingAttribute
     {ResourceName = null;
      SequenceNumber = 1;
      SourceConstructFlags = UnionCase;
      TypeDefinitions = null;
      TypeId = Microsoft.FSharp.Core.CompilationMappingAttribute;
      VariantNumber = 0;}|]|]
namespace Microsoft
namespace Microsoft.FSharp
namespace Microsoft.FSharp.Core
Multiple items
type CompilationMappingAttribute = inherit Attribute new: sourceConstructFlags: SourceConstructFlags -> CompilationMappingAttribute + 3 overloads member ResourceName: string member SequenceNumber: int member SourceConstructFlags: SourceConstructFlags member TypeDefinitions: Type array member VariantNumber: int

--------------------
new: sourceConstructFlags: SourceConstructFlags -> CompilationMappingAttribute
new: sourceConstructFlags: SourceConstructFlags * sequenceNumber: int -> CompilationMappingAttribute
new: resourceName: string * typeDefinitions: System.Type array -> CompilationMappingAttribute
new: sourceConstructFlags: SourceConstructFlags * variantNumber: int * sequenceNumber: int -> CompilationMappingAttribute
[<Struct>] type SourceConstructFlags = | None = 0 | SumType = 1 | RecordType = 2 | ObjectType = 3 | Field = 4 | Exception = 5 | Closure = 6 | Module = 7 | UnionCase = 8 | Value = 9 | KindMask = 31 | NonPublicRepresentation = 32

this.GetCustomAttributesData

Full Usage: this.GetCustomAttributesData

Returns: IList<CustomAttributeData> An list of custom attribute data items.

Returns the custom attributes data associated with the case.

Returns: IList<CustomAttributeData>

An list of custom attribute data items.

Example

 type Signal(signal: string) =
   inherit System.Attribute()
   member this.Signal = signal

 type Answer =
     | [<Signal("Thumbs up")>] Yes
     | [<Signal("Thumbs down")>] No

 let answerYes =
     typeof<Answer>
     |> FSharpType.GetUnionCases
     |> Array.find (fun x -> x.Name = "Yes")

 answerYes.GetCustomAttributesData()
Multiple items
type Signal = inherit Attribute new: signal: string -> Signal member Signal: string

--------------------
new: signal: string -> Signal
val signal: string
Multiple items
val string: value: 'T -> string

--------------------
type string = System.String
namespace System
Multiple items
type Attribute = member Equals: obj: obj -> bool member GetHashCode: unit -> int member IsDefaultAttribute: unit -> bool member Match: obj: obj -> bool static member GetCustomAttribute: element: Assembly * attributeType: Type -> Attribute + 7 overloads static member GetCustomAttributes: element: Assembly -> Attribute array + 15 overloads static member IsDefined: element: Assembly * attributeType: Type -> bool + 7 overloads member TypeId: obj
<summary>Represents the base class for custom attributes.</summary>

--------------------
System.Attribute() : System.Attribute
val this: Signal
type Answer = | Yes | No
val answerYes: obj
val typeof<'T> : System.Type
module Array from Microsoft.FSharp.Collections
val find: predicate: ('T -> bool) -> array: 'T array -> 'T
val x: obj
Evaluates to
  [|[FSI_0150+Signal("Thumbs up")]
      {AttributeType = FSI_0150+Signal;
       Constructor = Void .ctor(System.String);
       ConstructorArguments = seq ["Thumbs up"];
       NamedArguments = seq [];};
    [Microsoft.FSharp.Core.CompilationMappingAttribute((Microsoft.FSharp.Core.SourceConstructFlags)8, (Int32)0)]
      {AttributeType = Microsoft.FSharp.Core.CompilationMappingAttribute;
       Constructor = Void .ctor(Microsoft.FSharp.Core.SourceConstructFlags, Int32);
       ConstructorArguments = seq
                                [(Microsoft.FSharp.Core.SourceConstructFlags)8;
                                 (Int32)0];
       NamedArguments = seq [];}|]
namespace System
Multiple items
type String = interface IEnumerable<char> interface IEnumerable interface ICloneable interface IComparable interface IComparable<string> interface IConvertible interface IEquatable<string> interface IParsable<string> interface ISpanParsable<string> new: value: nativeptr<char> -> unit + 8 overloads ...
<summary>Represents text as a sequence of UTF-16 code units.</summary>

--------------------
System.String(value: nativeptr<char>) : System.String
System.String(value: char array) : System.String
System.String(value: System.ReadOnlySpan<char>) : System.String
System.String(value: nativeptr<sbyte>) : System.String
System.String(c: char, count: int) : System.String
System.String(value: nativeptr<char>, startIndex: int, length: int) : System.String
System.String(value: char array, startIndex: int, length: int) : System.String
System.String(value: nativeptr<sbyte>, startIndex: int, length: int) : System.String
System.String(value: nativeptr<sbyte>, startIndex: int, length: int, enc: System.Text.Encoding) : System.String
Multiple items
val seq: sequence: 'T seq -> 'T seq

--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
namespace Microsoft
namespace Microsoft.FSharp
namespace Microsoft.FSharp.Core
Multiple items
type CompilationMappingAttribute = inherit Attribute new: sourceConstructFlags: SourceConstructFlags -> CompilationMappingAttribute + 3 overloads member ResourceName: string member SequenceNumber: int member SourceConstructFlags: SourceConstructFlags member TypeDefinitions: Type array member VariantNumber: int

--------------------
new: sourceConstructFlags: SourceConstructFlags -> CompilationMappingAttribute
new: sourceConstructFlags: SourceConstructFlags * sequenceNumber: int -> CompilationMappingAttribute
new: resourceName: string * typeDefinitions: System.Type array -> CompilationMappingAttribute
new: sourceConstructFlags: SourceConstructFlags * variantNumber: int * sequenceNumber: int -> CompilationMappingAttribute
[<Struct>] type SourceConstructFlags = | None = 0 | SumType = 1 | RecordType = 2 | ObjectType = 3 | Field = 4 | Exception = 5 | Closure = 6 | Module = 7 | UnionCase = 8 | Value = 9 | KindMask = 31 | NonPublicRepresentation = 32

this.GetFields

Full Usage: this.GetFields

Returns: PropertyInfo array The fields associated with the case.

The fields associated with the case, represented by a PropertyInfo.

Returns: PropertyInfo array

The fields associated with the case.

Example

 type Shape =
     | Rectangle of width : float * length : float
     | Circle of radius : float
     | Prism of width : float * float * height : float

 typeof<Shape>
 |> FSharpType.GetUnionCases
 |> Array.map (fun unionCase ->
     unionCase.GetFields()
     |> Array.map (fun fieldInfo ->
         fieldInfo.Name,
         fieldInfo.PropertyType.Name))
type Shape = | Rectangle of width: float * length: float | Circle of radius: float | Prism of width: float * float * height: float
Multiple items
val float: value: 'T -> float (requires member op_Explicit)

--------------------
type float = System.Double

--------------------
type float<'Measure> = float
val typeof<'T> : System.Type
module Array from Microsoft.FSharp.Collections
val map: mapping: ('T -> 'U) -> array: 'T array -> 'U array
val unionCase: obj
val fieldInfo: obj
Evaluates to
 [|[|("width", "Double"); ("length", "Double")|];
   [|("radius", "Double")|];
   [|("width", "Double"); ("Item2", "Double"); ("height", "Double")|]|]

this.Name

Full Usage: this.Name

Returns: string

The name of the case.

Returns: string
Example

 type Weather = Rainy | Sunny

 typeof<Weather>
 |> FSharpType.GetUnionCases
 |> Array.map (fun x -> x.Name)
type Weather = | Rainy | Sunny
val typeof<'T> : System.Type
module Array from Microsoft.FSharp.Collections
val map: mapping: ('T -> 'U) -> array: 'T array -> 'U array
val x: obj
Evaluates to [|"Rainy", "Sunny"|]

this.Tag

Full Usage: this.Tag

Returns: int

The integer tag for the case.

Returns: int
Example

 type CoinToss = Heads | Tails

 typeof<CoinToss>
 |> FSharpType.GetUnionCases
 |> Array.map (fun x -> $"{x.Name} has tag {x.Tag}")
type CoinToss = | Heads | Tails
val typeof<'T> : System.Type
module Array from Microsoft.FSharp.Collections
val map: mapping: ('T -> 'U) -> array: 'T array -> 'U array
val x: obj
Evaluates to [|"Heads has tag 0"; "Tails has tag 1"|]

Type something to start searching.