Skip to content

Conversation

@michelebastione
Copy link
Contributor

Mirrors PR #886 on the maintenance branch

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @michelebastione, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the handling of double type conversions within the TypeHelper utility. It introduces a more robust parsing mechanism that first attempts culture-specific conversion, then falls back to invariant culture, and finally throws an explicit exception for values that cannot be reliably converted. This change aims to prevent silent data corruption and provide clearer feedback when invalid data is encountered during type mapping.

Highlights

  • Improved Double Parsing Logic: The ConvertDynamicToSpecificType method now prioritizes parsing double values using the config.Culture before falling back to CultureInfo.InvariantCulture.
  • Enhanced Error Handling for Double Conversion: Unparseable string values that cannot be converted to a double (even with invariant culture) will now throw an InvalidCastException instead of silently returning double.NaN.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@michelebastione michelebastione merged commit e2ae020 into mini-software:v1.x-maintenance Oct 16, 2025
1 check passed
@michelebastione michelebastione deleted the double-parsing-fixes_maintenance branch October 16, 2025 22:22
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses two edge cases in mapping double types. It now correctly uses the configured culture for parsing and throws an InvalidCastException on failure, which is more consistent with how other types are handled. The logic is sound. I've provided one suggestion to improve the readability of the new code.

Comment on lines +202 to +212
if (double.TryParse(Convert.ToString(itemValue, config.Culture), NumberStyles.Any, config.Culture, out var doubleValue))
{
newValue = doubleValue;
}
else
{
var invariantString = Convert.ToString(itemValue, CultureInfo.InvariantCulture);
newValue = double.TryParse(invariantString, NumberStyles.Any, CultureInfo.InvariantCulture, out var value)
? value
: throw new InvalidCastException($"Value \"{itemValue}\" cannot be cast to double");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic here is correct, but the nested structure combined with a ternary expression using throw can be a bit dense and harder to read. Refactoring this to a more standard if-else structure would improve code clarity and maintainability without altering the functionality.

                if (double.TryParse(Convert.ToString(itemValue, config.Culture), NumberStyles.Any, config.Culture, out var doubleValue))
                {
                    newValue = doubleValue;
                }
                else
                {
                    var invariantString = Convert.ToString(itemValue, CultureInfo.InvariantCulture);
                    if (double.TryParse(invariantString, NumberStyles.Any, CultureInfo.InvariantCulture, out var value))
                    {
                        newValue = value;
                    }
                    else
                    {
                        throw new InvalidCastException($"Value \"{itemValue}\" cannot be cast to double");
                    }
                }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant