Logo ionide-analyzers

StructDiscriminatedUnionAnalyzer

When a Discriminated Union only has primitive(-ish) field data you can consider to turn it into a struct.

Problem

type DU =
    | One
    | Two of a:int
    | Three of b:float

Fix

[<Struct>]
type DU =
    | One
    | Two of a:int
    | Three of b:float

Code fix

This analyzer has a code fix for Ionide:

code fix for EqualsNullAnalyzer

type DU =
  | One
  | Two of a: int
  | Three of b: float
argument a: int
Multiple items
val int: value: 'T -> int (requires member op_Explicit)

--------------------
type int = int32

--------------------
type int<'Measure> =
  int
argument b: float
Multiple items
val float: value: 'T -> float (requires member op_Explicit)

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

--------------------
type float<'Measure> =
  float
Multiple items
type StructAttribute =
  inherit Attribute
  new: unit -> StructAttribute

--------------------
new: unit -> StructAttribute

Type something to start searching.