-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Use CultureInfo.InvariantCulture when TryParsing minimal action parameters #32377
Comments
Thanks for contacting us. We're moving this issue to the |
Here's a list of TryParse methods I found taking an IFormatProvider:
I just ran something like the following in dotnet interactive: using System.Reflection;
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
var types = assemblies.SelectMany(a => a.GetTypes()).ToArray();
var staticMethods = types.SelectMany(t => t.GetMethods(BindingFlags.Public | BindingFlags.Static)).ToArray();
bool IsTryParseMethod(MethodInfo method)
{
if (method.Name != "TryParse" || method.ReturnType != typeof(bool))
{
return false;
}
var tryParseParameters = method.GetParameters();
if (tryParseParameters.Length > 2 &&
tryParseParameters[0].ParameterType == typeof(string))
{
return true;
}
return false;
}
var tryParseMethods = staticMethods.Where(IsTryParseMethod).ToArray();
tryParseMethods.Select(m => m.ToString()) |
Hi @halter73 can I try a PR on that 🙂 ? |
Absolutely! Thanks again for the null handling PR. Feel free to open a draft early or comment here if you have any questions or concerns. |
Follow up to #30248 (comment):
TryParse
on method on any parameter first, signatures supported:static bool TryParse(string, NumberStyles, IFormatProvider, int)
where theNumberStyles
parameter is required to useCultureInfo.InvariantCulture
as theIFormatProvider
.static bool TryParse(string, IFormatProvider, out T)
The text was updated successfully, but these errors were encountered: