Skip to content

Special-case enums in interpolated string handlers #76157

@stephentoub

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.)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions