[Solved] Need Converting Help C# to F#


Something like this should do the trick:

let getEnumDescription value = 
    let fi = 
        value.GetType().GetField(value.ToString())
    
    let attributes = 
        fi.GetCustomAttributes(typedefof<DescriptionAttribute>, false)
        |> Array.map (fun x -> x :?> DescriptionAttribute)

    if attributes.Length > 0 then
        attributes.[0].Description
    else 
        value.ToString()

Then you can call it like so:

let red = Color.Red |> getEnumDescription
let blue = Color.Blue |> getEnumDescription

printfn "Red is %s\nBlue is %s" red blue

//Red is Red
//Blue is Deep Blue

3

solved Need Converting Help C# to F#