| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="SmartEnumExtensions.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using System.Globalization; |
| | | 9 | | using MyNet.Humanizer.Display; |
| | | 10 | | using MyNet.Primitives; |
| | | 11 | | |
| | | 12 | | #pragma warning disable IDE0130 // Namespace does not match folder structure |
| | | 13 | | namespace MyNet.Humanizer; |
| | | 14 | | #pragma warning restore IDE0130 // Namespace does not match folder structure |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// Contains extension methods for humanizing Enums. |
| | | 18 | | /// </summary> |
| | | 19 | | public static class SmartEnumExtensions |
| | | 20 | | { |
| | | 21 | | extension(ISmartEnum value) |
| | | 22 | | { |
| | | 23 | | /// <summary> |
| | | 24 | | /// Returns the humanized display name using an explicit provider resolved from DI. |
| | | 25 | | /// </summary> |
| | | 26 | | /// <param name="provider">The display name provider.</param> |
| | | 27 | | /// <param name="culture">The culture to use when retrieving the display name.</param> |
| | | 28 | | /// <returns>The humanized display name of the SmartEnum value.</returns> |
| | | 29 | | public string HumanizeWith(IDisplayTextStrategy<ISmartEnum> provider, CultureInfo? culture = null) |
| | 0 | 30 | | => value.HumanizeWith(provider, DisplayTextOptions.Default, culture); |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// Returns the humanized display name using an explicit provider resolved from DI. |
| | | 34 | | /// </summary> |
| | | 35 | | /// <param name="provider">The display name provider.</param> |
| | | 36 | | /// <param name="options">The options to use when retrieving the display name.</param> |
| | | 37 | | /// <param name="culture">The culture to use when retrieving the display name.</param> |
| | | 38 | | /// <returns>The humanized display name of the SmartEnum value.</returns> |
| | | 39 | | public string HumanizeWith(IDisplayTextStrategy<ISmartEnum> provider, DisplayTextOptions options, CultureInfo? c |
| | | 40 | | { |
| | 0 | 41 | | ArgumentNullException.ThrowIfNull(provider); |
| | 0 | 42 | | return provider.GetDisplayText(value, options, culture.OrCurrent()); |
| | | 43 | | } |
| | | 44 | | } |
| | | 45 | | } |
| | | 46 | | |