< Summary

Information
Class: MyNet.Humanizer.Facade.TextHumanizer
Assembly: MyNet.Humanizer
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Humanizer/Facade/TextHumanizer.cs
Tag: 323_28699572109
Line coverage
88%
Covered lines: 8
Uncovered lines: 1
Coverable lines: 9
Total lines: 51
Line coverage: 88.8%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
Configure(...)50%2280%
Humanize(...)100%11100%
CreateDisplayTextService()100%11100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Humanizer/Facade/TextHumanizer.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="TextHumanizer.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Collections.Generic;
 9using System.Globalization;
 10using System.Threading;
 11using MyNet.Globalization.Culture;
 12using MyNet.Humanizer.Display;
 13using MyNet.Humanizer.Display.Registration;
 14
 15namespace MyNet.Humanizer.Facade;
 16
 17public static class TextHumanizer
 18{
 819    private static IDisplayTextService _service = CreateDisplayTextService();
 20    private static int _configured;
 21
 22    public static void Configure(IDisplayTextService service)
 23    {
 824        ArgumentNullException.ThrowIfNull(service);
 25
 826        if (Interlocked.Exchange(ref _configured, 1) == 1)
 27        {
 028            throw new InvalidOperationException("TextHumanizer has already been configured.");
 29        }
 30
 831        _service = service;
 832    }
 33
 34    /// <summary>
 35    /// Gets the display text for a given value of type T, using the appropriate display text strategy registered for th
 36    /// </summary>
 37    /// <param name="value">The value for which to get the display text.</param>
 38    /// <param name="options">The options to use when generating the display text.</param>
 39    /// <param name="culture">The culture to use for determining the display text.</param>
 40    /// <typeparam name="T">The type of the value.</typeparam>
 41    /// <returns>The display text for the given value.</returns>
 42    public static string Humanize<T>(T value, DisplayTextOptions options, CultureInfo? culture = null)
 10443        where T : notnull => _service.GetDisplayText(value, options, culture);
 44
 45    private static DisplayTextService CreateDisplayTextService()
 46    {
 847        var defaultRegistry = new DisplayTextStrategyRegistry(new Dictionary<Type, IDisplayTextStrategy>());
 848        return new(new DisplayTextStrategyResolver(defaultRegistry), new ThreadCultureContext());
 49    }
 50}
 51