| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="QuantifyExtensions.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using MyNet.Globalization.Localization.Translation; |
| | | 9 | | using MyNet.Humanizer.Display; |
| | | 10 | | using MyNet.Primitives.Conversion; |
| | | 11 | | |
| | | 12 | | #pragma warning disable IDE0130 // Namespace does not match folder structure |
| | | 13 | | namespace MyNet.Humanizer.Facade; |
| | | 14 | | #pragma warning restore IDE0130 // Namespace does not match folder structure |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// Provides extensions for formatting a <see cref="string"/> word as a quantity. |
| | | 18 | | /// </summary> |
| | | 19 | | public static class QuantifyExtensions |
| | | 20 | | { |
| | | 21 | | extension<TUnit>(Quantity<TUnit> quantity) |
| | | 22 | | where TUnit : struct, Enum |
| | | 23 | | { |
| | | 24 | | /// <summary> |
| | | 25 | | /// Formats the quantity by humanizing the unit and quantifying the value. The method uses the default display s |
| | | 26 | | /// </summary> |
| | | 27 | | /// <param name="format">A standard or custom numeric format string.</param> |
| | | 28 | | /// <returns>The formatted quantity string.</returns> |
| | 12 | 29 | | public string Humanize(string? format = null) => quantity.Humanize(DisplayStyle.Default, format); |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// Formats the quantity by humanizing the unit and quantifying the value. The method first humanizes the unit u |
| | | 33 | | /// </summary> |
| | | 34 | | /// <param name="style">The display style to use when humanizing the unit.</param> |
| | | 35 | | /// <param name="format">A standard or custom numeric format string.</param> |
| | | 36 | | /// <returns>The formatted quantity string.</returns> |
| | 21 | 37 | | public string Humanize(DisplayStyle style, string? format = null) => quantity.Unit.Humanize(new DisplayTextOptio |
| | | 38 | | } |
| | | 39 | | } |
| | | 40 | | |