Skip to content

[Feature]: AOT-safe value formatting for generated request building #2192

Description

@glennawatson

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions