Fix locale issue for numeric string conversions (#6194)

* Fix locale issue for numeric string conversions

Using a generated C# client from an application with a locale that formats numbers with a comma as a decimal separator will make the client send invalid numeric parameters to the API. Any numeric parameter with decimals will added to the URL with a comma ('0,15' instead of '0.15'), potentially breaking the API integration.
In my specific use case, the API interpreted '0,15' as '15', resulting in pretty funky errors.

This commit ensures that parameters are parsed with the invariation culture, fixing the mentioned error.

* Add missing reference to System.Globalization

* Update ClientUtils.mustache
This commit is contained in:
Jesper Nysteen 2020-05-10 16:41:03 +02:00 committed by GitHub
parent a986867a95
commit 7f58c57249
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -97,7 +98,7 @@ namespace {{packageName}}.Client
if (obj is ICollection collection) if (obj is ICollection collection)
return string.Join(",", collection.Cast<object>()); return string.Join(",", collection.Cast<object>());
return Convert.ToString(obj); return Convert.ToString(obj, CultureInfo.InvariantCulture);
} }
/// <summary> /// <summary>