Skip to content

Commit fc9484c

Browse files
committed
[#177] Enum-like unions can be used as dictionary keys
1 parent 4f93c6c commit fc9484c

3 files changed

Lines changed: 437 additions & 216 deletions

File tree

src/FSharp.SystemTextJson/Helpers.fs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ let isSkippableType (fsOptions: JsonFSharpOptionsRecord) (ty: Type) =
5656
let isValueOptionType (ty: Type) =
5757
ty.IsGenericType && ty.GetGenericTypeDefinition() = typedefof<ValueOption<_>>
5858

59+
let isEnumLikeUnion (ty: Type) =
60+
FSharpType.IsUnion(ty, true)
61+
&& FSharpType.GetUnionCases(ty, true)
62+
|> Array.forall (fun case -> case.GetFields().Length = 0)
63+
5964
[<AutoOpen>]
6065
type Helper =
6166
static member tryGetUnionCases(ty: Type, cases: UnionCaseInfo[] outref) =

0 commit comments

Comments
 (0)