Last active
August 29, 2015 14:00
-
-
Save kristopherjohnson/3849f6b12854b020c7d2 to your computer and use it in GitHub Desktop.
F# utility functions for Enum types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
module EnumUtil = | |
/// Return all values for an enumeration type | |
let EnumValues (enumType : Type) : seq<int> = | |
let values = Enum.GetValues enumType | |
let getValue (i : int) : int = downcast values.GetValue i | |
let lb = values.GetLowerBound 0 | |
let ub = values.GetUpperBound 0 | |
seq { lb .. ub } |> Seq.map getValue | |
/// Return minimum and maximum values for an enumeration type | |
let EnumValueRange (enumType : Type) : int * int = | |
let values = EnumValues enumType |> Seq.toList | |
(List.min values), (List.max values) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment