You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Special-case enums in interpolated string handlers #76157
Once Type.IsEnum is an intrinsic (#71685) and the static Enum.TryFormat has been added (#71590), we should be able to update the in-box interpolated string handlers to special-case enums and use TryFormat rather than calling ToString on them, which at a minimum boxes and worst-case allocates a result string. This can either be a long-term solution, or it can be a stop-gap until Enum itself implements ISpanFormattable, which we've said we'll only do if the JIT is updated to avoid boxing when using its methods.
(We can similarly special-case anywhere optimized formatting would be helpful, e.g. maybe in StringBuilder, in ValueStringBuilder, etc.)
Activity
mburbea commentedon Sep 26, 2022
In the mean time, I've used this pattern to some success since 6.0 to special case code for enums.
https://sharplab.io/#v2:C4LghgzgtgPgAgJgIwFgBQcAMACAygCzACcAHAGTACMA6AJQFcA7YASygFMBuddAbQCkWwAOLtG7IiwDGACmABPEuwD2AMxktmASi0AaQSLETpcxSvW5gkxgHMAwsqgliLCMsY7d2A6PGTZCkpqMnBImDoAuuhwAMzYiNh2ADwAKgB82ADe6Ni58XGhAGzYlMrKADbYALIyWtgAvGk5eS2B5jIpWtQAkhAAamDl9OwpZtgAZOPYACbsqmD05cAdda7YAKKM9FDcaAC+QA===
MichalPetryka commentedon Nov 12, 2022
#71685 has been merged so the first part has been unblocked here.