Skip to content
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

Closed
4 tasks
halter73 opened this issue May 4, 2021 · 4 comments
Closed
4 tasks
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc bug This issue describes a behavior which is not expected - a bug. feature-minimal-actions Controller-like actions for endpoint routing help wanted Up for grabs. We would accept a PR to help resolve this issue
Milestone

Comments

@halter73
Copy link
Member

halter73 commented May 4, 2021

Follow up to #30248 (comment):

  • Look for TryParse on method on any parameter first, signatures supported:
  • Use invariant culture always
@halter73 halter73 added bug This issue describes a behavior which is not expected - a bug. area-runtime feature-minimal-actions Controller-like actions for endpoint routing labels May 4, 2021
@halter73 halter73 added this to the Next sprint planning milestone May 4, 2021
@ghost
Copy link

ghost commented May 4, 2021

Thanks for contacting us.

We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@BrennanConroy BrennanConroy added the help wanted Up for grabs. We would accept a PR to help resolve this issue label May 12, 2021
@halter73
Copy link
Member Author

halter73 commented May 14, 2021

Here's a list of TryParse methods I found taking an IFormatProvider:

Boolean TryParse(System.String, System.Globalization.NumberStyles, System.IFormatProvider, System.Decimal ByRef)
Boolean TryParse[TEnum](System.String, Boolean, TEnum ByRef)
Boolean TryParse(System.String, System.IFormatProvider, System.Globalization.DateTimeStyles, System.DateTime ByRef)
Boolean TryParse(System.String, System.Globalization.NumberStyles, System.IFormatProvider, Byte ByRef)
Boolean TryParse(System.String, System.IFormatProvider, System.Globalization.DateTimeStyles, System.DateTimeOffset ByRef)
Boolean TryParse(System.String, System.Globalization.NumberStyles, System.IFormatProvider, Double ByRef)
Boolean TryParse(System.String, System.Globalization.NumberStyles, System.IFormatProvider, System.Half ByRef)
Boolean TryParse(System.String, System.Globalization.NumberStyles, System.IFormatProvider, Int16 ByRef)
Boolean TryParse(System.String, System.Globalization.NumberStyles, System.IFormatProvider, Int32 ByRef)
Boolean TryParse(System.String, System.Globalization.NumberStyles, System.IFormatProvider, Int64 ByRef)
Boolean TryParse(System.String, System.Globalization.NumberStyles, System.IFormatProvider, IntPtr ByRef)
Boolean TryParse(System.String, System.Globalization.NumberStyles, System.IFormatProvider, SByte ByRef)
Boolean TryParse(System.String, System.Globalization.NumberStyles, System.IFormatProvider, Single ByRef)
Boolean TryParse(System.String, System.IFormatProvider, System.TimeSpan ByRef)
Boolean TryParse(System.String, System.Globalization.NumberStyles, System.IFormatProvider, UInt16 ByRef)
Boolean TryParse(System.String, System.Globalization.NumberStyles, System.IFormatProvider, UInt32 ByRef)
Boolean TryParse(System.String, System.Globalization.NumberStyles, System.IFormatProvider, UInt64 ByRef)
Boolean TryParse(System.String, System.Globalization.NumberStyles, System.IFormatProvider, UIntPtr ByRef)
Boolean TryParse(System.String, System.String, System.Diagnostics.ActivityContext ByRef)
Boolean TryParse(System.String, System.Globalization.NumberStyles, System.IFormatProvider, System.Numerics.BigInteger ByRef)

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())

@wcontayon
Copy link
Contributor

Hi @halter73 can I try a PR on that 🙂 ?

@halter73
Copy link
Member Author

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.

@ghost ghost locked as resolved and limited conversation to collaborators Jul 28, 2021
@amcasey amcasey added area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed area-runtime labels Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc bug This issue describes a behavior which is not expected - a bug. feature-minimal-actions Controller-like actions for endpoint routing help wanted Up for grabs. We would accept a PR to help resolve this issue
Projects
None yet
Development

No branches or pull requests

4 participants