Skip to content

Commit

Permalink
Rewrite Enum and add {ISpanFormattable}.TryFormat (dotnet/runtime#78580)
Browse files Browse the repository at this point in the history
* Add generic Enum.TryFormat method

* Rewrite Enum using generic specialization per underlying type

Also revises the shape of the newly added Enum.TryFormat method and fixes tests accordingly.

* Use Enum.TryFormat in interpolated string handlers

* Implement ISpanFormattable on Enum

* Use generic Enum methods in more places

* Replace Unsafe.As with unmanaged pointers where possible

Reduces cost of the generic methods

* Simplify Enum_GetValuesAndNames QCall, fix handling of floats and doubles

This change avoids allocation of the temporary ulong[] array during EnumInfo initialization

Fixes dotnet/runtime#29266

* Fix mono's GetEnumNamesAndValues, and make ToObject handle float/double as well

* Fix perf gap and polish

* Undo update of Enum.GetTypeCode to include float/double

* Address PR feedback

* Accomodate net8.0 TFM update

* Fix InvalidCastException from GetEnumValues on mono when dealing with bool-based enums

Co-authored-by: Heath Baron-Morgan <[email protected]>
Co-authored-by: Jan Kotas <[email protected]>

Commit migrated from dotnet/runtime@62f3eb2
  • Loading branch information
stephentoub authored Dec 6, 2022
1 parent c582503 commit 9ca5933
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public PrintRange PrintRange
get { return _printRange; }
set
{
if (!Enum.IsDefined(typeof(PrintRange), value))
if (!Enum.IsDefined(value))
throw new InvalidEnumArgumentException(nameof(value), unchecked((int)value), typeof(PrintRange));

_printRange = value;
Expand Down

0 comments on commit 9ca5933

Please sign in to comment.