Is your feature request related to a problem? Please describe.
Follow-up to #18725 and #20919. Color is getting IFormattable support for configurable ToString formats. HslColor and HsvColor should get the same treatment for consistency.
Currently these types have a single ToString() that outputs a fixed format. There's no way to control alpha inclusion or output representation.
Describe the solution you'd like
Implement IFormattable on both HslColor and HsvColor with format specifiers following the same convention established in #20919: uppercase includes alpha, lowercase excludes it.
Proposed specifiers for HslColor:
| Specifier |
Output |
H |
hsl(h, s%, l%, a) — with alpha |
h |
hsl(h, s%, l%) — without alpha |
Proposed specifiers for HsvColor:
| Specifier |
Output |
V |
hsv(h, s%, v%, a) — with alpha |
v |
hsv(h, s%, v%) — without alpha |
Default ToString() behavior unchanged for both types.
Additional context
Is your feature request related to a problem? Please describe.
Follow-up to #18725 and #20919.
Coloris gettingIFormattablesupport for configurableToStringformats.HslColorandHsvColorshould get the same treatment for consistency.Currently these types have a single
ToString()that outputs a fixed format. There's no way to control alpha inclusion or output representation.Describe the solution you'd like
Implement
IFormattableon bothHslColorandHsvColorwith format specifiers following the same convention established in #20919: uppercase includes alpha, lowercase excludes it.Proposed specifiers for
HslColor:Hhsl(h, s%, l%, a)— with alphahhsl(h, s%, l%)— without alphaProposed specifiers for
HsvColor:Vhsv(h, s%, v%, a)— with alphavhsv(h, s%, v%)— without alphaDefault
ToString()behavior unchanged for both types.Additional context