-
-
Notifications
You must be signed in to change notification settings - Fork 758
Proposal: Add a TreatAsString
field to QueryAttribute
#1943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
I am open to suggestions on how to implement this functionality. In many of my project, both professional and personal, I find myself adding The solution could also work on types not owned by the implementer such as passing a GUID as a query parameter.
|
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.
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. |
@ChrisPulman I will work to get have the project build successfully and will provide and updated here again when it is. |
@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.
|
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:
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 ifToString()
is already implemented on a custom type.