Skip to content

Special-case enums in interpolated string handlers #76157

Closed

Description

@stephentoub

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

  1. added this to the 8.0.0 milestone on Sep 26, 2022
  2. self-assigned this
    on Sep 26, 2022
  3. mburbea commented on Sep 26, 2022

    @mburbea
  4. MichalPetryka commented on Nov 12, 2022

    @MichalPetryka
    Contributor

    #71685 has been merged so the first part has been unblocked here.

  5. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Nov 18, 2022
  6. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Dec 6, 2022
  7. ghost locked as resolved and limited conversation to collaborators on Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions