Skip to content

Commit

Permalink
Add work around for NativeAOT bug with enums and DefaultValues
Browse files Browse the repository at this point in the history
Enums are converted to integers with NativeAOT on attribute constructors. This work around is needed until that bug is fixed. See dotnet/runtime#100688
  • Loading branch information
phil-scott-78 committed Apr 5, 2024
1 parent 3ffa521 commit 86554ff
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions examples/Cli/Demo/Verbosity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ public VerbosityConverter()

public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
// NativeAOT will pass an integer when using the DefaultValue and an enum, so we need to manually convert
// that back to the enum
if (value is int intValue && Enum.IsDefined(typeof(Verbosity), intValue))
{
return (Verbosity)intValue;
}

if (value is string stringValue)
{
var result = _lookup.TryGetValue(stringValue, out var verbosity);
Expand Down

0 comments on commit 86554ff

Please sign in to comment.