Skip to content

refactor: change DefaultQuantities to use property initializer #1575

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

Closed
wants to merge 1 commit into from

Conversation

angularsen
Copy link
Owner

Fixup of #1555

@lipchev
Copy link
Collaborator

lipchev commented Jul 25, 2025

I believe there was a reason for this- if we use an eager initializer here, we couldn't allow for re-configuring the "default".
Also note, that you're editing the generated file.

Copy link

codecov bot commented Jul 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93%. Comparing base (5131d24) to head (abcdb72).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@          Coverage Diff           @@
##           master   #1575   +/-   ##
======================================
  Coverage      93%     93%           
======================================
  Files         311     311           
  Lines       28781   28781           
======================================
  Hits        26864   26864           
  Misses       1917    1917           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@angularsen
Copy link
Owner Author

angularsen commented Jul 25, 2025

Right, but I thought the idea was that this is the built-in provider. Any customizations happen further out, such as in MassInfo.CreateDefault(Func customizeUnits): #1555 (review) or by manipulating UnitsNetSetup.Default.

@lipchev
Copy link
Collaborator

lipchev commented Jul 25, 2025

The Mass.Info is currently read-only- in the other project I end up doing something like:

        /// <summary>
        ///     Configures a custom quantity for the default configuration.
        /// </summary>
        /// <typeparam name="TQuantity">The type of the quantity to configure.</typeparam>
        /// <typeparam name="TUnit">The type of the unit associated with the quantity, which must be an enumeration.</typeparam>
        /// <param name="createCustomConfigurationDelegate">
        ///     A delegate that creates a custom configuration for the quantity.
        /// </param>
        /// <returns>The current instance of <see cref="UnitsNet.UnitsNetSetup.DefaultConfigurationBuilder" /> for method chaining.</returns>
        public DefaultConfigurationBuilder ConfigureQuantity<TQuantity, TUnit>(Func<QuantityInfo<TQuantity, TUnit>> createCustomConfigurationDelegate)
            where TQuantity : IQuantity<TQuantity, TUnit>
            where TUnit : struct, Enum
        {
            _quantitiesSelector ??= new QuantitiesSelector(() => Quantity.DefaultProvider.Quantities);
            _quantitiesSelector.Configure(createCustomConfigurationDelegate);
            return this;
        }

so for a particular quantity we can override the default setter, by constructing it using the provided customization function. The action using the Quantity.Provider would end up constructing the QuantityInfo's before we are able to do anything.

@lipchev lipchev closed this Jul 25, 2025
@lipchev
Copy link
Collaborator

lipchev commented Jul 25, 2025

I've merged #1576

@angularsen angularsen deleted the agl/default-quantities branch July 26, 2025 02:05
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.

2 participants