Skip to content

Commit

Permalink
chore: modify code that is pointed out in the code review
Browse files Browse the repository at this point in the history
  • Loading branch information
filzrev committed Oct 9, 2024
1 parent a926285 commit 2d369d5
Showing 1 changed file with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -382,17 +382,16 @@ private static object CastInteger(ulong number, TypeCode typeCode)
}
else if (Regex.IsMatch(v, @"[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?")) //regular number
{
#pragma warning disable format
if ( byte.TryParse(v, NumberStyles.Integer, formatter.NumberFormat, out var byteValue )) { result = byteValue; }
else if (short.TryParse(v, NumberStyles.Integer, formatter.NumberFormat, out var shortValue )) { result = shortValue; }
else if ( int.TryParse(v, NumberStyles.Integer, formatter.NumberFormat, out var intValue )) { result = intValue; }
else if ( long.TryParse(v, NumberStyles.Integer, formatter.NumberFormat, out var longValue )) { result = longValue; }
else if (ulong.TryParse(v, NumberStyles.Integer, formatter.NumberFormat, out var ulongValue )) { result = ulongValue; }
if (byte.TryParse(v, NumberStyles.Integer, formatter.NumberFormat, out var byteValue)) { result = byteValue; }
else if (short.TryParse(v, NumberStyles.Integer, formatter.NumberFormat, out var shortValue)) { result = shortValue; }
else if (int.TryParse(v, NumberStyles.Integer, formatter.NumberFormat, out var intValue)) { result = intValue; }
else if (long.TryParse(v, NumberStyles.Integer, formatter.NumberFormat, out var longValue)) { result = longValue; }
else if (ulong.TryParse(v, NumberStyles.Integer, formatter.NumberFormat, out var ulongValue)) { result = ulongValue; }
#if NETFRAMEWORK
else if ( float.TryParse(v, NumberStyles.Float | NumberStyles.AllowThousands, formatter.NumberFormat, out var floatValue)) { result = floatValue; }
else if (double.TryParse(v, NumberStyles.Float | NumberStyles.AllowThousands, formatter.NumberFormat, out var doubleValue)) { result = doubleValue; }
else if (float.TryParse(v, NumberStyles.Float, formatter.NumberFormat, out var floatValue)) { result = floatValue; }
else if (double.TryParse(v, NumberStyles.Float, formatter.NumberFormat, out var doubleValue)) { result = doubleValue; }
#else
else if (double.TryParse(v, NumberStyles.Float | NumberStyles.AllowThousands, formatter.NumberFormat, out var doubleValue))
else if (double.TryParse(v, NumberStyles.Float, formatter.NumberFormat, out var doubleValue))
{
var floatValue = (float)doubleValue;
if (!float.IsNaN(floatValue) && !float.IsInfinity(floatValue)) // .NET 6 or later support float.IsNormal
Expand All @@ -405,7 +404,6 @@ private static object CastInteger(ulong number, TypeCode typeCode)
}
}
#endif
#pragma warning restore format
else
{
//we couldn't parse it, default to string, It's probably too big
Expand Down

0 comments on commit 2d369d5

Please sign in to comment.