Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ public ValueTask<IDictionary<string, object>> GetUIPropertiesAsync(PropertyInfo
}
}

var enumValues = Enum.GetValues(wrappedPropertyType).Cast<object>().ToList();
var enumValues = Enum.GetValues(wrappedPropertyType)
.Cast<Enum>()
.GroupBy(Convert.ToInt32)
Comment on lines +42 to +44
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deduplication logic uses Convert.ToInt32 which will fail for enums with underlying types other than int (e.g., long, byte, short). While HttpStatusCode uses int, this is a generic enum handler. Consider using Enum.GetUnderlyingType() to safely convert values regardless of the underlying type, or use GroupBy(x => x) with a custom comparer to avoid type-specific conversion altogether.

Suggested change
var enumValues = Enum.GetValues(wrappedPropertyType)
.Cast<Enum>()
.GroupBy(Convert.ToInt32)
var underlyingType = Enum.GetUnderlyingType(wrappedPropertyType);
var enumValues = Enum.GetValues(wrappedPropertyType)
.Cast<Enum>()
.GroupBy(x => Convert.ChangeType(x, underlyingType))

Copilot uses AI. Check for mistakes.
.Select(g => g.First())
.ToList();
var enumSelectListItems = enumValues.Select(x => new SelectListItem(x.ToString()!, x.ToString()!)).ToList();
if (isNullableEnum)
enumSelectListItems.Insert(0, new SelectListItem("-",""));
Expand Down
Loading