| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="DisplayTextService.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System.Globalization; |
| | | 8 | | using MyNet.Globalization.Culture; |
| | | 9 | | |
| | | 10 | | namespace MyNet.Humanizer.Display; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Current implementation of <see cref="IDisplayTextService"/> that retrieves display texts using registered display te |
| | | 14 | | /// </summary> |
| | | 15 | | /// <param name="resolver">The resolver used to obtain the appropriate display text strategy for a given type.</param> |
| | | 16 | | /// <param name="cultureContext">The culture context used to determine the current culture.</param> |
| | | 17 | | public class DisplayTextService(IDisplayTextStrategyResolver resolver, ICultureContext cultureContext) : IDisplayTextSer |
| | | 18 | | { |
| | | 19 | | /// <inheritdoc/> |
| | | 20 | | public string GetDisplayText<T>(T value, DisplayTextOptions options, CultureInfo? culture = null) |
| | | 21 | | where T : notnull |
| | | 22 | | { |
| | 116 | 23 | | var cultureToUse = culture ?? cultureContext.CurrentCulture; |
| | | 24 | | |
| | 116 | 25 | | return typeof(T) == value.GetType() ? resolver.GetRequired<T>().GetDisplayText(value, options, cultureToUse) : r |
| | | 26 | | } |
| | | 27 | | } |
| | | 28 | | |