Skip to content

Routing system should introduce some abstraction for converting route parameters to strings. #58416

@voroninp

Description

@voroninp

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I am working with typed ids:

public readonly record struct FooId(Guid Value);

If I use this value as a route parameter value and do not override ToString it is converted to string as FooId { Value = '....' }. That is obviously not what I want to have in a generated URL.

IMO, framework should not force my types to have a certain behavior. Writing parameter value to a URL is effectively a serialization, hence there should be the same level of flexibility/extensibility.

While framework offers outbound parameter transformers, they are not connected to the types of parameter values.

Describe the solution you'd like

I'd like ASP.NET to introduce a specific interface:

public interface IRouteParaemterValueStringConverter<TParameterValue>
{
    string Convert(TParameterValue value);
}

Its default implementation can just convert to string.

Additional context

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions