Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mark-pro
Copy link
Contributor

The proposal arises from the need to pass custom types or structs which might represent types with rules and conversions. Most of these types can override ToString() which can then be called when constructing query parameters.

For example:

record readonly struct ZipCode(ushort ZipCode) {
    public override string ToString() =>
        ZipCode.ToString();
}

To solve the problem the proposal seeks to add a field to the QueryAttribute called TreatAsString.

The new field is used when the query string is created and simply calls the ToString() function on a type.

There is a workaround that is not documented. The current workaround is to implement IFormattable on the type, which feels redundant if ToString() is already implemented on a custom type.

@mark-pro
Copy link
Contributor Author

I am open to suggestions on how to implement this functionality. In many of my project, both professional and personal, I find myself adding IFormattable to those types which feels a little clunky when I really need that complex type to be a string.

The solution could also work on types not owned by the implementer such as passing a GUID as a query parameter.

GetUser([Query(TreatAsString = true)] Guid userId).

The proposal arises from the need to pass custom types or structs which might represent types with rules and conversions.

For example:

```csharp
record readonly struct ZipCode(ushort ZipCode) {
    public override string ToString() =>
        ZipCode.ToString();
}
```

To solve the problem the proposal seeks to add a field to the QueryAttribute called `TreatAsString`.

The new field is used when the query string is created and simply calls the `ToString()` function on a type.

There is a workaround that is not documented. The current workaround is to implement `IFormattable` on the type, which feels redundant if `ToString()` is already implemented on a custom type.
@ChrisPulman
Copy link
Member

Hi @mark-pro , Thank you for your PR, please could you update it so that it builds, I cannot see the build logs so am unaware if there was any issue during the Github actions build.

@mark-pro
Copy link
Contributor Author

mark-pro commented Jun 25, 2025

@ChrisPulman I will work to get have the project build successfully and will provide and updated here again when it is.

@mark-pro
Copy link
Contributor Author

mark-pro commented Jun 25, 2025

@ChrisPulman I have updated the unit tests. They are now passing in my fork of the project. The project runs the build action to completion.

The latest build run is awaiting approval.

GitHub
The automatic type-safe REST library for .NET Core, Xamarin and .NET. Heavily inspired by Square's Retrofit library, Refit turns your REST API into a live interface. - Proposal: Add a `TreatAsS...

@codecov
Copy link

codecov bot commented Jul 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.09%. Comparing base (6ebeda5) to head (8d692fd).
Report is 198 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1943      +/-   ##
==========================================
- Coverage   87.73%   83.09%   -4.64%     
==========================================
  Files          33       37       +4     
  Lines        2348     2650     +302     
  Branches      294      381      +87     
==========================================
+ Hits         2060     2202     +142     
- Misses        208      362     +154     
- Partials       80       86       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ChrisPulman ChrisPulman merged commit acd0af6 into reactiveui:main Jul 11, 2025
2 of 3 checks passed
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants