Follow-up from #2174 (v13.0.0).
Is your feature request related to a problem?
After #2174, request shaping is reflection-free, but value formatting for path params (and query values, once those go inline) still goes through IUrlParameterFormatter / DefaultUrlParameterFormatter, which uses reflection for enums and TypeConverter. So the reflection-free/AOT guarantee only holds at the request-shaping layer, not value formatting: enum, TypeConverter, and other non-primitive values can still hit trimming/AOT warnings or format wrong under AddRefitGeneratedClient / NativeAOT.
Describe the solution you'd like
Format statically-known parameter types in generated code without runtime reflection, matching DefaultUrlParameterFormatter output and still honoring a custom IUrlParameterFormatter when one is set.
Describe alternatives you've considered
- Keep calling
IUrlParameterFormatter for everything (status quo): simplest, but leaves reflection in the path and breaks the AOT promise for enum/TypeConverter values.
- Emit direct formatting only for provably-simple types and fall back to the formatter (and the reflection builder) for the rest: a reasonable first cut.
Describe suggestions on how to achieve the feature
- Simple types (
IsSimpleType, Parser.Request.Helpers.cs): emit direct ToString(CultureInfo.InvariantCulture) / ToString("D") matching DefaultUrlParameterFormatter.
- Enums: emit the resolved string at compile time from the enum symbol (plus any
[EnumMember]/Display/Description the default formatter honors) instead of runtime enum reflection.
- Custom
IUrlParameterFormatter: still call it, but pass the static typeof(TParam) and the generator-emitted ICustomAttributeProvider (GeneratedParameterAttributeProvider) instead of reflecting ParameterInfo.
- Anything not provably safe falls back to the reflection builder (RF006 then flags it at compile time).
Additional context
Deferred from the #2174 review. Best done after the extra path-parameter type coverage (Guid / DateTime / DateTimeOffset / decimal / double / float / enum), since that work is what surfaces types that need real formatting.
Follow-up from #2174 (v13.0.0).
Is your feature request related to a problem?
After #2174, request shaping is reflection-free, but value formatting for path params (and query values, once those go inline) still goes through
IUrlParameterFormatter/DefaultUrlParameterFormatter, which uses reflection for enums andTypeConverter. So the reflection-free/AOT guarantee only holds at the request-shaping layer, not value formatting: enum,TypeConverter, and other non-primitive values can still hit trimming/AOT warnings or format wrong underAddRefitGeneratedClient/ NativeAOT.Describe the solution you'd like
Format statically-known parameter types in generated code without runtime reflection, matching
DefaultUrlParameterFormatteroutput and still honoring a customIUrlParameterFormatterwhen one is set.Describe alternatives you've considered
IUrlParameterFormatterfor everything (status quo): simplest, but leaves reflection in the path and breaks the AOT promise for enum/TypeConvertervalues.Describe suggestions on how to achieve the feature
IsSimpleType,Parser.Request.Helpers.cs): emit directToString(CultureInfo.InvariantCulture)/ToString("D")matchingDefaultUrlParameterFormatter.[EnumMember]/Display/Descriptionthe default formatter honors) instead of runtime enum reflection.IUrlParameterFormatter: still call it, but pass the statictypeof(TParam)and the generator-emittedICustomAttributeProvider(GeneratedParameterAttributeProvider) instead of reflectingParameterInfo.Additional context
Deferred from the #2174 review. Best done after the extra path-parameter type coverage (Guid / DateTime / DateTimeOffset / decimal / double / float / enum), since that work is what surfaces types that need real formatting.