< Summary - Syki

Information
Class: Syki.Back.Shared.EnumExtensions
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Shared/Extensions/EnumExtensions.cs
Tag: 56_26538939494
Line coverage
91%
Covered lines: 21
Uncovered lines: 2
Coverable lines: 23
Total lines: 67
Line coverage: 91.3%
Branch coverage
100%
Covered branches: 12
Total branches: 12
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetDescription(...)100%66100%
IsIn(...)100%44100%
ToEnum(...)100%210%
IsValid(...)100%11100%
Is(...)100%210%
DiffInMinutes(...)100%22100%

File(s)

/home/runner/work/syki/syki/Back/Shared/Extensions/EnumExtensions.cs

#LineLine coverage
 1namespace Syki.Back.Shared;
 2
 3public static class EnumExtensions
 4{
 5    public static string GetDescription(this Enum value)
 6    {
 227        if (value == null)
 8        {
 29            return string.Empty;
 10        }
 11
 2012        var attribute = value.GetType()
 2013            .GetField(value.ToString())!
 2014            .GetCustomAttributes(typeof(DescriptionAttribute), inherit: false);
 15
 2016        if (attribute is DescriptionAttribute[] source && source.Length != 0)
 17        {
 1818            return source.First().Description;
 19        }
 20
 221        return value.ToString();
 22    }
 23
 24    public static bool IsIn(this Enum source, params Enum[] valuesToCheck)
 25    {
 2426        if (valuesToCheck == null || valuesToCheck.Length == 0)
 27        {
 428            return false;
 29        }
 30
 2031        return valuesToCheck.Contains(source);
 32    }
 33
 34    public static T ToEnum<T>(this string value)
 35    {
 036        return (T)Enum.Parse(typeof(T), value, true);
 37    }
 38
 39    public static bool IsValid(this Enum value)
 40    {
 1241        return Enum.IsDefined(value.GetType(), value);
 42    }
 43
 44    public static bool Is(this DayOfWeek dayOfWeek, Day day)
 45    {
 046        return day.ToString() == dayOfWeek.ToString();
 47    }
 48
 49    public static int DiffInMinutes(this Hour hourA, Hour hourB)
 50    {
 3251        if (hourA > hourB)
 52        {
 853            (hourA, hourB) = (hourB, hourA);
 54        }
 55
 3256        var hourAHour = int.Parse(hourA.ToString().Substring(1, 2));
 3257        var hourAMinute = int.Parse(hourA.ToString().Substring(4, 2));
 58
 3259        var hourBHour = int.Parse(hourB.ToString().Substring(1, 2));
 3260        var hourBMinute = int.Parse(hourB.ToString().Substring(4, 2));
 61
 3262        var hours = hourBHour - hourAHour;
 3263        var minutes = hourBMinute - hourAMinute;
 64
 3265        return hours * 60 + minutes;
 66    }
 67}