< Summary - Syki

Information
Class: Syki.Back.Commands.CommandToDescriptionMapper
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Commands/CommandToDescriptionMapper.cs
Tag: 4_16869239191
Line coverage
0%
Covered lines: 0
Uncovered lines: 6
Coverable lines: 6
Total lines: 22
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%210%
ToCommandDescription(...)0%620%
GetCommandDescriptionAttribute(...)100%210%

File(s)

/home/runner/work/syki/syki/Back/Commands/CommandToDescriptionMapper.cs

#LineLine coverage
 1using System.Collections.Concurrent;
 2
 3namespace Syki.Back.Commands;
 4
 5public static class CommandToDescriptionMapper
 6{
 07    private static readonly ConcurrentDictionary<string, CommandDescriptionAttribute> _attributes = new();
 8
 9    public static string ToCommandDescription(this string value)
 10    {
 011        if (value.IsEmpty()) return value;
 12
 013        return _attributes.GetOrAdd(value, GetCommandDescriptionAttribute(value)).Description;
 14    }
 15
 16    private static CommandDescriptionAttribute GetCommandDescriptionAttribute(this string value)
 17    {
 018        var type = typeof(ICommand).Assembly.GetType(value)!;
 019        var customAttributes = (CommandDescriptionAttribute[])type.GetCustomAttributes(typeof(CommandDescriptionAttribut
 020        return customAttributes[0];
 21    }
 22}