-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add CultureForParameters option to RestClientOptions for culture-aware parameter formatting #2323
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: dev
Are you sure you want to change the base?
Conversation
…er methods Co-authored-by: alexeyzimarev <2821205+alexeyzimarev@users.noreply.github.com>
Deploying restsharp with
|
| Latest commit: |
1fb26de
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://aee672ce.restsharp.pages.dev |
| Branch Preview URL: | https://copilot-fix-cultureinfo-para.restsharp.pages.dev |
|
@copilot some tests failed so it must be a breaking change. it'd be good to make the new behaviour to be opt-in. |
Co-authored-by: alexeyzimarev <2821205+alexeyzimarev@users.noreply.github.com>
Made the invariant culture formatting opt-in by adding new method overloads with a request.AddParameter("value", 1.234, useInvariantCulture: true);Commit: 8059e9b |
|
@copilot Instead of new parameter, add a property to |
…e parameter formatting Co-authored-by: alexeyzimarev <2821205+alexeyzimarev@users.noreply.github.com>
Co-authored-by: alexeyzimarev <2821205+alexeyzimarev@users.noreply.github.com>
Added Usage: var options = new RestClientOptions { CultureForParameters = CultureInfo.InvariantCulture };
using var client = new RestClient(options);
var request = new RestRequest();
request.AddParameter(client, "value", 1.234); // "1.234"
// Or for default parameters:
client.AddDefaultParameter("value", 1.234);Commit: 1fb26de |
Description
Adds a
CultureForParametersproperty toRestClientOptionsthat allows configuring the culture used when formattingIFormattableparameter values (like doubles, decimals, dates). This addresses the issue where values like1.234are formatted as"1,234"in locales that use comma as decimal separator (e.g., da-DK), breaking API compatibility.Changes:
CultureForParametersproperty toRestClientOptions(defaults tonullwhich uses local culture)ObjectExtensions.ToStringWithCulture<T>()- usesIFormattable.ToString(null, culture)for formattable types, falls back toToString()otherwiseRestClientExtensionsfor adding default parameters with culture formatting:AddDefaultParameter<T>(name, value)AddDefaultQueryParameter<T>(name, value)AddDefaultUrlSegment<T>(name, value)FormatValue<T>(value)helper methodRestRequestExtensions.Culture.csfor adding parameters to requests using client's culture:AddParameter<T>(request, client, name, value, encode)AddOrUpdateParameter<T>(request, client, name, value, encode)AddQueryParameter<T>(request, client, name, value, encode)AddUrlSegment<T>(request, client, name, value, encode)Fixes #2270
Purpose
This pull request is a:
Checklist
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.