< Summary

Information
Class: TeleFlow.Telegram.I18n.Fluent.I18nArgument
Assembly: TeleFlow.Framework.I18n.Fluent
File(s): /_/src/TeleFlow.Framework.I18n.Fluent/I18nArgument.cs
Line coverage
64%
Covered lines: 9
Uncovered lines: 5
Coverable lines: 14
Total lines: 57
Line coverage: 64.2%
Branch coverage
54%
Covered branches: 6
Total branches: 11
Branch coverage: 54.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)0%1150%
op_Implicit(...)100%11100%
IsValidIdentifier(...)60%121071.42%

File(s)

/_/src/TeleFlow.Framework.I18n.Fluent/I18nArgument.cs

#LineLine coverage
 1namespace TeleFlow.Telegram.I18n.Fluent;
 2
 3/// <summary>
 4/// Represents one named value supplied to a Fluent message without dictionaries or anonymous-object reflection.
 5/// </summary>
 6public readonly record struct I18nArgument
 7{
 8    public I18nArgument(string name, object? value)
 9    {
 51610        ArgumentException.ThrowIfNullOrWhiteSpace(name);
 11
 51612        if (!IsValidIdentifier(name))
 13        {
 014            throw new ArgumentException(
 015                "Fluent argument names must start with an ASCII letter and contain only ASCII letters, digits, '-' or '_
 016                nameof(name));
 17        }
 18
 19        Name = name;
 20        Value = value;
 51621    }
 22
 23    /// <summary>
 24    /// Gets the Fluent variable name without the leading <c>$</c>.
 25    /// </summary>
 26    public string Name { get; }
 27
 28    /// <summary>
 29    /// Gets the application value converted by the Fluent adapter at formatting time.
 30    /// </summary>
 31    public object? Value { get; }
 32
 33    public static implicit operator I18nArgument((string Name, object? Value) argument)
 34    {
 51635        return new I18nArgument(argument.Name, argument.Value);
 36    }
 37
 38    private static bool IsValidIdentifier(string name)
 39    {
 51640        if (!char.IsAsciiLetter(name[0]))
 41        {
 042            return false;
 43        }
 44
 518645        for (var index = 1; index < name.Length; index++)
 46        {
 207747            var character = name[index];
 48
 207749            if (!char.IsAsciiLetterOrDigit(character) && character is not '-' and not '_')
 50            {
 051                return false;
 52            }
 53        }
 54
 51655        return true;
 56    }
 57}