Skip to content

Commit

Permalink
Handle enum literals that are not a defined value of the enum
Browse files Browse the repository at this point in the history
Fixes #30832
  • Loading branch information
ajcvickers committed May 9, 2023
1 parent a9a2411 commit 589ec1c
Show file tree
Hide file tree
Showing 2 changed files with 225 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/EFCore.Design/Design/Internal/CSharpHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,9 @@ public virtual string Literal(Enum value, bool fullName = false)
var name = Enum.GetName(type, value);

return name == null
? GetCompositeEnumValue(type, value, fullName)
? type.IsDefined(typeof(FlagsAttribute), false)
? GetCompositeEnumValue(type, value, fullName)
: $"({type.DisplayName(fullName: true, compilable: true)}){UnknownLiteral(Convert.ChangeType(value, Enum.GetUnderlyingType(type)))}"
: GetSimpleEnumValue(type, name, fullName);
}

Expand Down
Loading

0 comments on commit 589ec1c

Please sign in to comment.