Skip to content

Making the ToString paramters optional (IFormattable) #1553

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lipchev
Copy link
Collaborator

@lipchev lipchev commented Apr 19, 2025

  • removed the ToString(IFormatProvider?) overload from the IQuantity interface
  • removed the ToString overloads from the generated quantities (and HowMuch)
  • replaced the usages of ToString(IFormatProvider?) in the tests

duplicate of #1552

- removed the `ToString(IFormatProvider?)` overload from the IQuantity interface
- removed the `ToString` overloads from the generated quantities (and HowMuch)
- replaced the usages of `ToString(IFormatProvider?)` in the tests
@lipchev
Copy link
Collaborator Author

lipchev commented Apr 19, 2025

Hm, I was expecting there to be a very small size difference compared to #1552, but

before: 2.19 MB (2 301 440 bytes)
after: 2.18 MB (2 287 616 bytes)
#1552 : 2.17 MB (2 286 080 bytes) 😮

I don't know what to make of these numbers..

Anyway, I was also a little surprised by the number of breaking changes that this caused in the tests (non-generated).. I initially found the ToString extensions a little awkward, but I now I think they might be the better option..

@@ -167,15 +167,15 @@ public void LengthTimesSpecificWeightEqualsPressure()
public void ToStringReturnsCorrectNumberAndUnitWithDefaultUnitWhichIsMeter()
{
var meter = Length.FromMeters(5);
string meterString = meter.ToString(CultureInfo.InvariantCulture);
string meterString = meter.ToString(null, CultureInfo.InvariantCulture);
Copy link
Owner

Choose a reason for hiding this comment

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

This I don't like, c# users expect certain ToString() signatures to exist and having to use named parameters or pass null is awkward.

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