Numeric format strings: retarget net10.0, add section separators, composite formatting and TryFormat - #2171
Open
vladimir-pecanac-main wants to merge 1 commit into
Conversation
…posite formatting and TryFormat - Retarget both projects from net8.0 to net10.0. - Lift test packages: Microsoft.NET.Test.Sdk 18.9.0, xunit 2.9.3, xunit.runner.visualstudio 4.0.0, coverlet.collector 10.0.1. - CustomFormatStrings: add Accounting, BlankZero and EmptyThirdSection so the semicolon section separator the article now teaches is runnable, including the counter-intuitive case where an empty third section is ignored. - StandardFormatStrings: add FixedPointPrecisionDecimal, Aligned, AlignedInterpolated and TryFormatFixedPoint. - Tests pin the rounding difference between double and decimal under "F2", the composite format item's alignment component, and both TryFormat paths (big enough buffer and too small a buffer). - Tidy: StandardFormatsStrings.cs renamed to StandardFormatStrings.cs (and its test file likewise) to match the class name, and CustomFormatStringsTests moved to the same namespace as the rest of the test project.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supports the republish of Standard and Custom Numeric Format Strings.
Retarget and package lift
net8.0tonet10.0.Microsoft.NET.Test.Sdk17.6.0 to 18.9.0,xunit2.4.2 to 2.9.3,xunit.runner.visualstudio2.4.5 to 4.0.0,coverlet.collector6.0.0 to 10.0.1.New sample code, because the article gains two sections that had no runnable code
CustomFormatStrings.Accounting,.BlankZeroand.EmptyThirdSectioncover the semicolon section separator.EmptyThirdSectionexists because the behaviour is counter-intuitive and worth pinning:"#,##0.00;(#,##0.00);"formats0.0as0.00, since an empty section is ignored and the value falls back to the first one. Blanking zero needs an empty literal instead, which is whatBlankZeroshows.StandardFormatStrings.Alignedand.AlignedInterpolatedshow the composite format item's alignment component,{0,12:N2}and{value,-12:N2}.StandardFormatStrings.TryFormatFixedPointwrites into aSpan<char>and returnsfalserather than allocating when the buffer is too small.StandardFormatStrings.FixedPointPrecisionDecimalexists so the article's rounding correction has a test behind it. The article previously saidF2rounds withMidpointRounding.AwayFromZero, which is true fordecimaland false fordouble:1.005formats as1.00as adoubleand1.01as adecimal. Both directions are now pinned.Tidy
StandardFormatsStrings.csrenamed toStandardFormatStrings.csto match the class it holds, and the matching test file likewise. Git tracks both as renames.CustomFormatStringsTests.csmoved fromStandardAndCustomNumericFormatStringsTeststoStandardAndCustomFormatStringsTests, the namespace the rest of the test project already uses.Verification (SDK 10.0.302)
Previously 13 tests; the 14 added cases are the new methods plus the two
TryFormatpaths and the two rounding directions.